Variables and Data Types
Variables in JavaScript are containers used to store data values. You can declare variables using var, let, or const:
var: Function-scoped, hoisted, rarely used in modern code.let: Block-scoped, can be reassigned.const: Block-scoped, cannot be reassigned.
Example:
let name = 'Alice';
const age = 25;
var isStudent = true;JavaScript Data Types:
- Primitive Types:
string,number,boolean,undefined,null,symbol,bigint - Reference Types:
objects,arrays,functions
Use typeof to check the type of a variable:
console.log(typeof name); // 'string'