JavaScript ECMA2024 Presentation
JavaScript ECMA2024 Presentation
2024
• Introduced in ES6
• A class is a blueprint for objects
Inheritance
• w3schools.com
• developer.mozilla.org
• ECMA Official Docs
OOP Example
• let person = {
name: "Alice",
greet() { console.log(`Hi, I'm ${this.name}`); }
};
person.greet();
Class Example
• class Car {
constructor(brand) {
this.brand = brand;
}
drive() { console.log(`${this.brand} is driving`); }
}
let myCar = new Car("Toyota");
myCar.drive();
Inheritance Example
• class Animal {
speak() { console.log("Animal speaks"); }
}
class Dog extends Animal {
speak() { console.log("Dog barks"); }
}
let d = new Dog();
d.speak();
Destructuring Example
• function sum(...nums) {
return nums.reduce((a, b) => a + b);
}
let nums = [1, 2, 3];
console.log(sum(...nums));
Modules Example
• // add.js
export function add(x, y) { return x + y; }
// main.js
import { add } from './add.js';
DOM Example
• document.querySelector(".box").style.backgroundColor = "blue";
Interactivity Example
• document.getElementById("btn").onclick = function() {
alert("Button clicked!");
};
Selector Example
• let el = document.querySelector("#myId");
el.style.color = "green";
JSON Example