Functions & Scope

JavaScript Fundamentals14 pts

Back

Functions: Reusable Code Blocks

Functions are reusable blocks of code. They help organize code, avoid repetition, and make programs easier to understand and maintain.

Arrow functions (=>) are a shorter way to write functions. They're great for simple operations and are widely used in modern JavaScript.

Your Turn: Write a Function

Output:
  • Define a function named double
  • double(3) should equal 6
  • Should work with negative numbers
  • Should handle zero

Scope determines where variables can be accessed. Variables declared with let/const are block-scoped (only available in their { } block).

Which keyword creates block-scoped variables?
Select an answer