Tsallaka zuwa abun ciki
Justice Tech School

Declarations, Expressions and Hoisting

A function declaration is hoisted and can be called before it appears. A function expression is not. Arrow functions are always expressions.

Example
console.log(add(2, 3));
function add(a, b) { return a + b; }
const mul = function (a, b) { return a * b; };
const div = (a, b) => a / b;
console.log(mul(2, 3), div(6, 3));

Exercise

Return a value.

function f() {  1; }

Quiz Test

Can you call a function declaration before it is written?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.