JavaScript is a high-level, client-side scripting language used to make web pages interactive and dynamic.
👉 It works with:
<script>
document.write("Hello World");
</script>
;Variables store data values.
let x = 10;
const y = 20;
var z = 30;
var → old methodlet → block scopeconst → constant valuelet name = "Ali";
let age = 20;
+ - * / %== === !=&& || !let sum = 5 + 3;
if (x > 5) {
console.log("Greater");
} else {
console.log("Smaller");
}
for (let i = 0; i < 5; i++) {
console.log(i);
}
A function is a block of code that performs a task.
function greet() {
alert("Hello!");
}
function add(a, b) {
return a + b;
}
Events are actions performed by the user.
onclickonchangeonloadonmouseover<button onclick="alert('Clicked')">Click Me</button>
DOM allows JavaScript to access and modify HTML elements.
document.getElementById("demo").innerHTML = "Hello JS";
let fruits = ["Apple", "Banana", "Mango"];
let person = {
name: "Ali",
age: 20
};
setTimeout(() => {
alert("Hello");
}, 2000);
function validate() {
let x = document.forms["myForm"]["name"].value;
if (x == "") {
alert("Name must be filled out");
}
}
let and constconst add = (a, b) => a + b;
User Action → Event Trigger → JavaScript Code → DOM Update → Result Display
✔ JavaScript is case-sensitive
✔ Use === for strict comparison
✔ Place scripts at end of <body> for performance
✔ Avoid global variables
✔ Use let/const instead of var
JavaScript = Interactivity
Used for:
Key concepts:
👉 Works with HTML + CSS to build dynamic websites.
Open this section to load past papers