No this binding
Uses lexical this
ES6 (ECMAScript 2015) and later versions introduced modern features that make JavaScript:
let count = 1;count = 2;
const appName = "StudyVault";let → block scopedconst → block scoped + immutable bindingconsole.log(a); // errorlet a = 10;const name = "Asha";const msg = `Hello ${name}`;const multi = `Line 1Line 2`;const user = { name: "Riya", city: "Pune" };
const { name, city } = user;const { name: username, age = 18 } = user;const [a, b] = [10, 20];const [first, , third, ...rest] = [1, 2, 3, 4, 5];const arr = [1, 2];const newArr = [...arr, 3]; // spreadfunction sum(...nums) { // rest return nums.reduce((a, b) => a + b, 0);}function greet(name = "Guest") { return `Hello ${name}`;}function test(a = b, b = 2) {}// error (TDZ)const add = (a, b) => a + b;No this binding
Uses lexical this
No arguments object
Use rest instead
Cannot be constructor
Cannot use new
const obj = { value: 10, fn: () => console.log(this.value),};
obj.fn(); // undefinedconst name = "Asha";
const user = { name, greet() { return `Hi ${this.name}`; },};// old wayconst { add } = require("./math.js");
// exportexport function add(a, b) { return a + b;}
// importimport { add } from "./math.js";export default function () {}class User { constructor(name) { this.name = name; }
greet() { return `Hi ${this.name}`; }}Promise.all([p1, p2]);Promise.race([p1, p2]);Promise.allSettled([p1, p2]);all
waits for all
race
first resolved/rejected
allSettled
waits all (no fail)
user?.profile?.email;const value = input ?? "default";0 || "default"; // "default"0 ?? "default"; // 0const by defaulttry { const response = await fetch("/api/data"); if (!response.ok) { throw new Error(`HTTP ${response.status}`); } const data = await response.json(); console.log(data);} catch (error) { console.error("Request failed:", error.message);}