Nodejs-Cheatsheet
๐ Hello World // hello.js
console.log("Hello, World!"); ๐ก Tip: Run your script with node hello.js . ๐ฆ Variables & Data Types let age = 25;
const name = "Maxon";
let isAdmin = true;
let scores = [95, 88, 76];
let user = { name: "Maxon", age: 25 };
console.log(`${name} is ${age} years old.`); ๐ก Tip: Use const for constants and let for reassignable variables. Avoid var . ๐ Control Flow for (let i = 1; i <= 5; i++) {
if (i % 2 === 0) console.log(`${i} is Even`);
else console.log(`${i} is Odd`);
} ๐ก Tip: Try for...of and for...in loops for arrays and objects. ๐ Functions function add(a, b) {
return a + b;
}
const multiply = (a, b) => a * b;
console.log("Sum:", add(5, 3));
console.log("Product:", multiply(4, 2)); ๐ก Tip: Use arrow functions for concise, modern syntax. ๐ฆ Modules (Import/Export) // math.js
export function add(a, b) {
return a + b;
}
// main.js
import { add } from "./math.js";
console.log(add(10, 5)); ๐ก…