JavaScript Cheatsheet
1. Basic Syntax
Operation Syntax/Example
Declare variable (ES6) let x = 5; const y = 10;
Console output [Link]("Hello World");
Data types String, Number, Boolean, Object, Array, Null, Undefined, Symbol
Type checking typeof x
2. Operators
Operator Description Example
Arithmetic + - * / % ++ -- let sum = 5 + 3;
Assignment = += -= *= /= x += 5;
Comparison == === != !== > < >= <= x === 10
Logical && || ! if (x > 5 && y < 10)
Ternary condition ? expr1 : expr2 let status = age > 18 ? 'adult' : 'minor';
3. Conditional Statements
if (condition) {
// code if true
} else if (condition) {
// code if true
} else {
// code if all false
switch (value) {
case 1:
// code for case 1
break;
JavaScript Cheatsheet
case 2:
// code for case 2
break;
default:
// code if no cases match
4. Loops
Loop Example
for loop for (let i = 0; i < 5; i++) { [Link](i); }
while loop let i = 0; while (i < 5) { [Link](i); i++; }
do...while let i = 0; do { [Link](i); i++; } while (i < 5);
for...of (arrays) for (let value of array) { [Link](value); }
for...in (objects) for (let key in object) { [Link](key, object[key]); }