JavaScript Variables and Data Types Guide
javascript
variables
data-types
coercion
scope
Variables
Declaration Types
var
: Function-scoped, can be redeclared, hoisted.let
: Block-scoped, cannot be redeclared, not hoisted.const
: Block-scoped, immutable reference.
Scope
- Global Scope: Variables accessible everywhere.
- Function Scope: Variables declared with
var
inside a function. - Block Scope: Variables declared with
let
orconst
inside{}
.
Data Types
Primitive Types
string
:"Hello, World!"
number
:42, 3.14, -7
boolean
:true
,false
undefined
: Declared but not assigned.null
: Intentionally empty value.symbol
: Unique and immutable identifiers.bigint
: Large integers (12345678901234567890n
).
Reference Types
Object
:{ key: 'value' }
Array
:[1, 2, 3]
Function
:() => {}