Node.js Backend Fundamentals

Lesson 3 of 6

Functions and Modules

Functions

JavaScript

ES Modules

Split code across files with import/export (module files need a real Node.js project, so this example is read-only):

// math.js
export function add(a, b) {
  return a + b;
}

// app.js
import { add } from './math.js';
console.log(add(2, 3)); // 5

Set "type": "module" in package.json to use ES modules natively.

📝 Functions & Modules Quiz

Passing score: 70%
  1. 1.To bring a named export into another file you use the ____ keyword.

  2. 2.Arrow functions are declared with the => syntax.