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)); ๐Ÿ’ก…

Post a Comment