Lesson 6 of 55 · javascript
Functions – declarations, expressions & arrow functions
Duration: 11 mins
Function Declaration:
function add(a,b){ return a+b; }
Function Expression:
const multiply = function(a,b){ return a*b; };
Arrow Function (ES6):
const divide = (a,b) => a / b;
Key differences:
- Arrow functions lexically bind
this. - No
argumentsobject – use rest parameters (...args). - Cannot be used as constructors.
Example: Arrow function preserving this
const obj = {
value: 42,
getValue: () => this.value // `this` refers to the surrounding scope (window), NOT obj!
};