Javascript Tutorial
Javascript Tutorial
1. Introduction to JavaScript
JavaScript (JS) is a high-level, interpreted programming language widely used to create
dynamic and interactive web applications. It is one of the core technologies of the web
along with HTML and CSS.
Key Features
• Lightweight and versatile
• Cross-platform compatibility
• Event-driven and asynchronous
• Supports OOP and functional programming
2. Basics of JavaScript
2.1 Variables
var name = "John"; // function-scoped
let age = 25; // block-scoped
const PI = 3.1416; // block-scoped, constant value
2.3 Operators
• Arithmetic: + - * / % **
• Comparison: == === != !== > < >= <=
• Logical: && || !
• Assignment: = += -= *= /=
3. Functions
3.1 Function Declaration
function greet(name) {
return `Hello, ${name}`;
}
5. DOM Manipulation
document.getElementById("myId").innerText = "Updated";
document.querySelector(".myClass").style.color = "red";
Event Listeners:
document.getElementById("btn").addEventListener("click", () => {
alert("Button clicked!");
});
6. Advanced JavaScript
6.1 Closures
• Closures exist due to lexical environment and lexical scope, allowing inner
functions to access variables from their outer function even after the outer function
has returned.
function outer() {
let count = 0;
return function inner() {
count++;
return count;
}
}
const counter = outer();
console.log(counter());
console.log(counter());
8. Conclusion
JavaScript is an essential skill for any software developer. By mastering its concepts from
basics to advanced levels, you can build interactive web applications, scalable backend
systems, and cross-platform apps.