In JavaScript, variables are containers that store data values. They can be declared using three different keywords: var, let, and const.
var: This keyword is used to declare a variable that is function-scoped or globally scoped. It allows for variable redeclaration and hoisting.
let: This keyword declares a block-scoped variable, meaning it is limited to the block in which it is defined. It does not allow redeclaration within the same scope.
const: This keyword is used to declare a block-scoped variable that cannot be reassigned. A constant's value must be assigned at the time of declaration and cannot be changed.
Here is an example that demonstrates the use of these variable declarations:
// Using var
var name = 'John';
console.log(name); // Output: John
// Using let
let age = 30;
age = 31; // Allowed
console.log(age); // Output: 31
// Using const
const birthYear = 1993;
console.log(birthYear); // Output: 1993
// birthYear = 1994; // This will throw an error
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?