My First Steps in JavaScript: A Simple Breakdown
Source: Dev.to
Variables in JavaScript
let
Used for values that can change later.
let age = 20;
age = 21;
const
Used when the value should not be changed.
const PI = 3.14;
var
The old way of declaring variables. Not recommended now because it creates confusion with scope.
Data Types in JavaScript
Primitive Types
- String →
"Hello" - Number →
23,45.6 - Boolean →
trueorfalse - Null → empty value
- Undefined → no value assigned
- BigInt → very large numbers
- Symbol → unique values
Non-Primitive Types
- Object
- Array
- Function
Undefined vs Null
undefined
Means a variable exists but has no value yet.
let x;
console.log(x); // undefined
null
Means intentionally empty. We set it manually when something should have no value.
let data = null;