Skip to content

JavaScript Essentials for Node

Programming Node.js Difficulty 1/5

Beginning of the lesson

JavaScript Essentials for Node

The core JavaScript you need before you build with Node.js

Big Idea: Node.js lets you run JavaScript on your computer, outside the browser. Before you build servers and tools, you need a solid grip on the building blocks of the language: values, variables, functions, objects, and arrays. Master these and the rest of Node feels easy.
By the end you will be able to:
  • declare variables with let and const and know which to pick,
  • name the primitive types and check them with typeof,
  • build text with template strings,
  • write functions and arrow functions,
  • store data in objects and arrays and read it back.

1. How Node runs your code

You write JavaScript in a file that ends in .js. Then you ask Node to run it from your terminal:

node app.js

Node reads your file top to bottom and does exactly what it says. Anything you console.log(...) is printed in the terminal.

1 2 3 Write app.js node app.js runs it Output in the terminal
You write JavaScript in a file, Node runs it line by line, and console.log prints the result.

2. Variables: let and const

A variable is a labelled box that holds a value. In modern JavaScript you make one with let or const.

  • let — use it when the value will change later (a score, a counter).
  • const — use it when the value should stay the same (a name, a setting). This is the safer default.
let score = 0;        // can change later
const name = 'Ada';   // stays the same

score = 10;           // OK, let can be reassigned
console.log(score);   // 10
console.log(name);    // Ada

// name = 'Bob';      // TypeError: Assignment to constant variable.
Analogy: Think of a variable as a labelled jar. let is a jar you can empty and refill. const is a jar with the lid glued on — you cannot swap what it points to. Reach for const first, and switch to let only when you truly need to reassign.

Continue this lesson on YourAIZone

The full lesson has the complete explanation, worked examples, common mistakes, tests with instant checking and an AI tutor. Start right away as a guest, or create an account to keep your progress.

In the full lesson

  • The complete explanation
  • Worked examples
  • Common mistakes and how to avoid them
  • Test questions: 15
  • AI tutor that answers questions about the topic
  • Progress tracking for students, parents and teachers