-
Variables:
let x = 10; // Block-scoped, mutable const y = 20; // Block-scoped, immutable var z = 30; // Function-scoped, avoid using
-
Data Types:
// Primitive types let str = "Hello"; // String let num = 42; // Number let bool = true; // Boolean let nothing = null; // Null let undef; // Undefined let big = 9007199254740991n; // BigInt let sym = Symbol("id"); // Symbol // Objects let obj = { name: "Alice", age: 25 }; // Object let arr = [1, 2, 3]; // Array let func = () => console.log("Hi!"); // Function
- Arithmetic:
+
,-
,*
,/
,%
,**
- Comparison:
===
,!==
,<
,>
,<=
,>=
- Logical:
&&
,||
,!
- Assignment:
=
,+=
,-=
,*=
,/=
-
Conditional Statements:
if (x > 10) { console.log("Greater than 10"); } else if (x === 10) { console.log("Exactly 10"); } else { console.log("Less than 10"); }
-
Loops:
for (let i = 0; i < 5; i++) { console.log(i); } while (x > 0) { x--; } do { x++; } while (x < 5);
-
Function Declaration:
function add(a, b) { return a + b; }
-
Arrow Function:
const multiply = (a, b) => a * b;
-
Default Parameters:
const greet = (name = "Guest") => console.log(`Hello, ${name}`);
-
Object Access:
let person = { name: "Alice", age: 25 }; console.log(person.name); // Dot notation console.log(person["age"]); // Bracket notation
-
Array Methods:
let arr = [1, 2, 3]; arr.push(4); // Add to end arr.pop(); // Remove from end arr.shift(); // Remove from start arr.unshift(0); // Add to start arr.map(x => x * 2); // Transform array arr.filter(x => x > 1); // Filter array arr.reduce((sum, x) => sum + x, 0); // Reduce array
-
Template Literals:
let name = "Alice"; console.log(`Hello, ${name}!`);
-
Destructuring:
let { name, age } = person; let [first, second] = arr;
-
Spread and Rest:
let arr2 = [...arr, 4, 5]; let sum = (...nums) => nums.reduce((a, b) => a + b, 0);
-
Promises:
const fetchData = () => new Promise((resolve, reject) => { resolve("Data fetched"); }); fetchData().then(data => console.log(data)).catch(err => console.log(err));
-
ES6 Module:
// module.js export const add = (a, b) => a + b; // main.js import { add } from './module.js'; console.log(add(2, 3));
-
CommonJS:
// module.js module.exports = { add }; // main.js const { add } = require('./module');
-
Interactive Tutorials
- JavaScript.info: Comprehensive tutorials with interactive examples.
- MDN Web Docs: Official and detailed reference for JavaScript.
-
Courses
- FreeCodeCamp JavaScript: Hands-on exercises and projects.
- Codecademy JavaScript: Beginner-friendly course with an interactive environment.
-
Books
- Eloquent JavaScript (Free Online): A great in-depth book for all levels.
- You Don’t Know JS (GitHub): Deep dive into JavaScript internals.
-
Practice Platforms
- HackerRank JavaScript Challenges
- Codewars: Practice solving coding problems with JavaScript.