javascript 🐾



📌 1. Introduction

JavaScript is a high-level, interpreted, object-oriented programming language.

Used mainly for web development to add interactivity to websites.





🧩 2. Basics

// Single-line comment
/* Multi-line comment */

var x = 10;    // function-scoped (old)
let y = 20;    // block-scoped
const z = 30;  // block-scoped constant




🔢 3. Data Types

Primitive: String, Number, Boolean, undefined, null, Symbol, BigInt

Non-Primitive: Object, Array, Function





🔁 4. Operators

Arithmetic: + – * / % **

Assignment: = += -= *=

Comparison: == === != !== > < >= <=

Logical: && || !

Type: typeof, instanceof





🧱 5. Control Structures

if (condition) {
  // code
} else if (condition) {
  // code
} else {
  // code
}

switch (key) {
  case value:
    break;
  default:
}

Loops:

for (let i = 0; i < 5; i++) { }
while (condition) { }
do { } while (condition);




🧰 6. Functions

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

// Arrow function
const subtract = (a, b) => a – b;




📦 7. Arrays

let fruits = [“apple”, “banana”];
fruits.push(“orange”);
fruits.pop();
fruits.length;

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




🧱 8. Objects

let person = {
  name: “John”,
  age: 30,
  greet: function() {
    console.log(“Hi”);
  }
};

console.log(person.name);




🌐 9. DOM Manipulation

document.getElementById(“demo”).innerHTML = “Hello!”;
document.querySelector(“.btn”).style.color = “red”;

Events:

document.getElementById(“btn”).addEventListener(“click”, function() {
  alert(“Clicked!”);
});




🧪 10. JSON

let obj = { name: “John”, age: 30 };
let jsonStr = JSON.stringify(obj);
let parsed = JSON.parse(jsonStr);




⏳ 11. Timing

setTimeout(() => {
  console.log(“Hello after 1 sec”);
}, 1000);

setInterval(() => {
  console.log(“Every second”);
}, 1000);




🔄 12. ES6+ Features

Let & Const

Arrow Functions

Template Literals: Hello, ${name}

Destructuring: let {name, age} = person;

Spread Operator: […arr1, …arr2]

Promises / Async-Await





🌐 13. Fetch API

fetch(“https://api.example.com&#8221;)
  .then(res => res.json())
  .then(data => console.log(data))
  .catch(err => console.error(err));




🧠 14. Miscellaneous

== vs ===: Strict equality checks type too.

null vs undefined: null is assigned, undefined is default.

NaN is a number: typeof NaN === “number”



Design a site like this with WordPress.com
Get started