Master modern ES6 arrow function syntax, 1-line implicit returns, lexical this binding, and clean inline callbacks.
Learn how variables act as labeled containers for data using const, let, and var to manage lexical scope and reassignment safely in modern applications.
ES6 introduced arrow functions (() => {}), offering a concise syntax for writing function expressions.
Arrow functions reduce boilerplate code, make functional array methods (.map(), .filter()) elegant, and lexically bind the this keyword.
If an arrow function body consists of a single expression, you can omit the curly braces {} and the return keyword, causing the expression to evaluate and return implicitly:
// Traditional Function Expression
const squareTraditional = function(x) {
return x * x;
};
// Arrow Function with Explicit Return
const squareExplicit = (x) => {
return x * x;
};
// Arrow Function with Implicit Return (Concise 1-liner!)
const squareImplicit = (x) => x * x;
console.log(squareImplicit(5)); // 25
() => console.log("Hello").x => x * 2.(a, b) => a + b.({ key: value }). Otherwise, JavaScript misinterprets curly braces as a function block!// WRONG: Returns undefined because braces are interpreted as a block!
const makeUserWrong = (name) => { username: name };
// CORRECT: Parentheses tell JS this is an object literal!
const makeUserCorrect = (name) => ({ username: name });
console.log(makeUserCorrect("Alex")); // { username: "Alex" }
Use arrow functions for clean callbacks and utility expressions. Next, let's understand how the Scope Chain searches for variables!