Pre-requisites for the Node.js

 These are the some topics which you must know before starting Node.js

  1. Variables,
  2. Functions,
  3. Objects,
  4. Arrays,
  5. Asynchronous programming (callbacks, promises, async/await),
  6. ES6+ features

1. ✅ Variables – (Storing values)

Used to store data like numbers, text, etc.

let name = "Avinash";
const age = 25;
var city = "Patna";
  • let and const are preferred (ES6+).

  • const = value doesn’t change.

  • let = value can change.


2. πŸ”§ Functions – (Reusable code blocks)

Used to do a task when called.

function greet() {
  console.log("Hello!");
}

greet(); // Output: Hello!

You can also pass values:

function add(a, b) {
  return a + b;
}

console.log(add(2, 3)); // Output: 5

3. πŸ“¦ Objects – (Group related data)

Store data as key–value pairs.

const person = {
  name: "Avinash",
  age: 25,
  city: "Patna"
};

console.log(person.name); // Output: Avinash

4. πŸ“š Arrays – (List of values)

Store multiple items in one variable.

const fruits = ["apple", "banana", "orange"];

console.log(fruits[1]); // Output: banana

You can loop through arrays:

fruits.forEach(fruit => console.log(fruit));

5. ⏳ Asynchronous Programming

Runs tasks without blocking other code. Useful for things like fetching data or reading files.

a. Callback:

function greetLater(callback) {
  setTimeout(() => {
    callback("Hello!");
  }, 1000);
}

greetLater(msg => console.log(msg)); // Output after 1 sec: Hello!

b. Promise:

const promise = new Promise((resolve, reject) => {
  setTimeout(() => resolve("Done!"), 1000);
});

promise.then(result => console.log(result)); // Output: Done!

c. Async/Await:

async function showMessage() {
  const result = await promise;
  console.log(result); // Output: Done!
}
showMessage();

6. πŸš€ ES6+ Features (Modern JavaScript)

Some cool new features in modern JS:

a. Arrow Functions:

const greet = name => console.log(`Hello, ${name}`);
greet("Avinash");

b. Template Strings:

let name = "Avinash";
console.log(`My name is ${name}`);

c. Destructuring:

const person = { name: "Avinash", age: 25 };
const { name, age } = person;

d. Spread Operator:

const numbers = [1, 2, 3];
const newNumbers = [...numbers, 4, 5];


Comments

Popular posts from this blog

How to Upload Your Local Project to GitHub Properly

YouTube Videos, Translation, AI Tools Aur Hindi Mein Dekhne Ka Experience

How to Build a Telegram Bot Using Node.js – Step-by-Step Guide