How do you declare a variable in JavaScript?
a) var, let, const
b) int, float, double
c) String, Number, Boolean
d) define, declare, constant
Answer:
a) var, let, const
Explanation:
In JavaScript, you can declare variables using var
, let
, or const
. Each keyword has a different scope and behavior.
var
is function-scoped, while let
and const
are block-scoped. const
is used for declaring variables that should not be reassigned.
Example of declaring variables:
var x = 10;
let y = 20;
const z = 30;