noknow.dev
Sign inSign up
Course overview
JavaScript Fundamentals
0 / 7 lessons0%

Getting Started

  • Hello, World!
  • Variables: let and const
  • Numbers and Math

Decisions & Loops

  • if / else — Making Decisions
  • for Loops

Functions

  • Defining Functions
  • Arrow Functions

Arrow Functions

0m 00s

A shorter function syntax

Arrow functions are a more concise way to write functions — especially useful for short ones:

// Regular function
function square(x) {
  return x * x
}

// Arrow function — same result
const square = (x) => {
  return x * x
}

// Even shorter: when the body is a single expression, return is implicit
const square = (x) => x * x

console.log(square(5))  // 25

When to use which?

  • Short conversions or calculations → arrow function
  • Methods on objects → regular function
  • Everything else → personal preference

Your task

Write three arrow functions:

  1. double(x) → returns x × 2
  2. isEven(n) → returns true if n is even
  3. greet(name) → returns "Hey, [name]!"
Back
javascriptCtrl+Enter to run
Output

Click "Run" to execute your code.