Loading lesson path
Concept visual
Start at both ends
If you're new to JavaScript, don't worry! Here are the key concepts you need to know before diving into Node.js. We'll cover the essentials with simple examples. You can run these examples directly in your browser's console or in a.js file using Node.js.
Before starting with Node.js, you should be familiar with these JavaScript concepts:
Formula
Asynchronous programming (callbacks, promises, async/await)This page will give short examples of essential JavaScript concepts needed for Node.js development. For a greater understanding for JavaScipt, visit our JavaScript Tutorial.
// Variables (let, const, var)
let name = 'Node.js';
const version = 20;
// Function declaration function greet(user) {
return `Hello, ${user}!`; // Template literal (ES6)
}
// Arrow function (ES6+)
const add = (a, b) => a + b;
console.log(greet('Developer')); // Hello, Developer!
console.log(add(5, 3)); // 8// Object const user = {
name: 'Alice', age: 25, greet() {
console.log(`Hi, I'm ${this.name}`);
}
};
// Array const colors = ['red', 'green', 'blue'];
// Array methods (ES6+)
colors.forEach(color => console.log(color));
const lengths = colors.map(color => color.length);// 1. Callbacks (traditional) function fetchData(callback) {
setTimeout(() => {
callback('Data received!');
}, 1000);
}
// 2. Promises (ES6+)
const fetchDataPromise = () => {
return new Promise((resolve) => {
setTimeout(() => resolve('Promise resolved!'), 1000);
});
};Formula
// 3. Async/Await (ES8 +)async function getData() {
const result = await fetchDataPromise();
console.log(result);
}
getData(); // Call the async function
Destructuring & Template Literals (ES6+)
const { name } = user;
console.log(`Hello, ${name}!`);let
(mutable), const
(immutable), var
(legacy)Regular, arrow functions, and methods Objects & Arrays:
require()
Formula
(CommonJS) and import/export(ES6)
Formula
try/catch blocksNode.js Support let / const
Yes (since Node 6+)Yes (since Node 4+)
Yes (since Node 6+)
Yes (since Node 4+)
Yes (since Node 0.12+)
Yes (since Node 7.6+)