P3.3: JS Functions & Scope

Functions are blocks of reusable logic. Scope determines the accessibility of variables declared in the code.


1. Declaring Functions

Functions are created using declarations or modern ES6 arrow expressions:

// Classic Declaration
function add(a, b) {
  return a + b;
}

// ES6 Arrow Function (Prevalent in React)
const multiply = (a, b) => a * b;
Marijn Haverbeke

Marijn HaverbekeView Profile 🔗

Real-World Developer Case Study
12 Years Exp
RoleAuthor of Eloquent JavaScript
Salary₹70 Lakhs/yr equivalent
CompanyCodeMirror
Core Tech Stack
JavaScript CompilersText EditorsCodeMirror

Functions are the building blocks of abstraction. Understand how functions closure works—they remember the variables of the scope they were created in.


🎓 Practice Assignment Tasks

  • Write a function `greetUser` that takes a name parameter and returns a greeting string.
  • Test both classic and arrow syntax.
Stuck? Hints available
// Write your JavaScript logic here
// Click 'Run Code' to see console outputs below
🔒 Code requirements not met yet. Complete the tasks above.
🔒 Complete the Practice Assignment above to unlock completion.
Advertisement
NS
Ask Nextsem
AI Mode
NS
Home
Course
Playground