← Lesson
BitWithBite
JavaScript · Quick Reference

Lesson 7 — Functions Cheat Sheet

JavaScript
In one line: A function is a named, reusable block of code that performs a specific task. You define it once and call it as many times as you need. Think of a function as a recipe: you write...

Key Ideas

1What is a Function?. A function is a named, reusable block of code that performs a specific task. You define it once and call it as many times as you need. Think of a function as a recipe:...
2Function Declarations. The classic way to create a function uses the function keyword, followed by a name, parentheses for parameters, and a block body. The defining feature of declarations ...
3Function Expressions. A function expression assigns an anonymous (or named) function to a variable. Unlike declarations, function expressions are not hoisted — you can only call them after ...
4Arrow Functions (ES6). Arrow functions, introduced in ES2015, provide a shorter syntax for writing function expressions. They use the => token instead of the function keyword. Beyond brev...
5Parameters & Arguments. Parameters are the named placeholders in the function definition. Arguments are the actual values you pass when calling the function. JavaScript is flexible: you can p...

Code Examples

// Hoisting demo: call before definition works! console.log(greet("Alice")); // Works! "Hello, Alice!" function greet(name) { return `Hello, ${name}!`; } // Multi-parameter function function add(a, b) { return a + b; } console.log(add(3, 7)); // 10 /...
// Function expression — NOT hoisted const multiply = function(a, b) { return a * b; }; console.log(multiply(4, 6)); // 24 // Named function expression (useful in stack traces) const factorial = function calcFactorial(n) { if (n <= 1) return 1; r...
// Full arrow function const add = (a, b) => { return a + b; }; // Implicit return (single expression — no braces, no return) const double = x => x * 2; console.log(double(7)); // 14 // No params: use empty parens const greet = () => "Hello, Wo...