Skip to the content.

Angular > JavaScript


JavaScript Fundamentals

Get started with JavaScript, the programming language of the web. Learn how to build interactive and dynamic behavior in your web applications.


๐Ÿ“ฆ Variables & Data Types

let name = "Alice";
const age = 25;
let isStudent = true;
let greeting = `Hello, my name is ${name} and I am ${age} years old.`;
console.log(greeting);

๐Ÿง  Operators & Control Flow

let score = 85;
if (score > 90) {
  console.log("A");
} else if (score > 75) {
  console.log("B");
} else {
  console.log("C");
}

for (let i = 0; i < 3; i++) {
  if (i === 1) continue;
  console.log(i);
}

๐Ÿงฉ Functions & Scope

function greet(name = "User") {
  return `Hello, ${name}`;
}

const add = (a, b) => a + b;

function outer() {
  let count = 0;
  return function inner() {
    return ++count;
  };
}

const counter = outer();
console.log(counter()); // 1
console.log(counter()); // 2

๐Ÿ—ƒ๏ธ Arrays & Objects

let fruits = ["apple", "banana"];
fruits.push("cherry");
fruits.forEach(fruit => console.log(fruit));

const user = {
  name: "Bob",
  age: 30,
  address: { city: "New York", zip: 10001 }
};

let { name, address: { city } } = user;
console.log(`${name} lives in ${city}`);

๐ŸŒ DOM Manipulation

const heading = document.getElementById("main-heading");
heading.innerText = "Updated Heading";
heading.style.color = "blue";

const newItem = document.createElement("li");
newItem.textContent = "New Item";
document.querySelector("ul").appendChild(newItem);

๐Ÿ–ฑ๏ธ Events & Interactivity

document.getElementById("submitBtn").addEventListener("click", function() {
  alert("Form Submitted!");
});

document.getElementById("nameInput").addEventListener("input", function(e) {
  console.log("You typed:", e.target.value);
});

๐Ÿงช Error Handling & Debugging

try {
  let result = riskyFunction();
  console.log(result);
} catch (error) {
  console.error("An error occurred:", error.message);
} finally {
  console.log("Cleanup done.");
}

๐Ÿš€ Modern JavaScript (ES6+)

const user = { name: "Eve", age: 22 };
const { name, age } = user;
const clone = { ...user };

async function fetchData() {
  try {
    let res = await fetch("https://api.example.com/data");
    let data = await res.json();
    console.log(data);
  } catch (e) {
    console.error(e);
  }
}

References


๐Ÿ”— Related Topics: