JavaScript Expressions & Operators
Learn about JavaScript expressions and operators with interactive examples.

1. Defining Functions

Expressions and operators are the building blocks of JavaScript computations. There are several ways to define them.

Declaration
JavaScript Code
Live JavaScript representation with highlighted changes
// Function Declaration
function square(number) {
return number * number;
}
Expression
JavaScript Code
Live JavaScript representation with highlighted changes
// Function Expression
const square = function(number) {
return number * number;
};
Arrow Function
JavaScript Code
Live JavaScript representation with highlighted changes
// Arrow Function
const square = (number) => number * number;

2. Recursion & the Call Stack

A function can call itself. This is called recursion. Let's visualize the call stack with a factorial function.

JavaScript Code
Live JavaScript representation with highlighted changes
function factorial(n) {
if (n === 0 || n === 1) {
return 1;
}
return n * factorial(n - 1);
}
factorial(5);
Call Stack
Result
Console Output