A comprehensive guide to learn JavaScript with clear explanations, practical examples, and modern ES6+ features for aspiring developers.
Built specifically for students and self-learners who want to understand JavaScript from the ground up with a structured approach.
No prior programming experience required
Practical code you can use immediately
ES6+ features and best practices
Progressive difficulty with clear structure
Comprehensive curriculum covering everything from basics to advanced concepts
Master the core concepts including variables, data types, operators, and control flow structures.
Deep dive into JavaScript objects, their properties, methods, and function behavior patterns.
Learn arrow functions, destructuring, spread operators, async/await, and more.
Create interactive web pages by mastering Document Object Model manipulation techniques.
Write clean, maintainable code following industry-standard conventions and patterns.
Apply your knowledge building practical applications like form validators and dynamic UIs.
Learn the differences between var, let, and const and when to use each one
// var - function scoped
var studName = 'Abdullah';
var studAge = 15;
// let - block scoped, can change
let counter = 0;
counter = 1; // ✓ Allowed
// const - block scoped, cannot change
const PI = 3.14159;
// PI = 3.14; // ✗ Error: Assignment to constant variable
| Feature | var | let | const |
|---|---|---|---|
| Scope | Function | Block | Block |
| Re-declaration | Allowed | Not Allowed | Not Allowed |
| Re-assignment | Allowed | Allowed | Not Allowed |
| Must Initialize | No | No | Yes |
| Modern Usage | Avoid | When value changes | Default choice |
Understanding primitive and composite data types in JavaScript
Primitive data types contain a single literal value such as a number or a string.
| Data Type | Description | Example |
|---|---|---|
| boolean | Contains only two values: true or false | let isActive = true; |
| null | Represents intentional absence of value | let data = null; |
| number | Positive/negative numbers and decimals | let age = 25; let pi = 3.14; |
| string | Alphanumeric characters in quotes | let name = "Abdullah"; |
Composite data types store collections of multiple related values.
| Data Type | Description |
|---|---|
| Objects | Collection of properties and functions |
| Functions | Collection of statements to achieve a specific task |
| Arrays | Collection of values in adjacent memory locations |
Master the essential operators for calculations, comparisons, and logic
Perform mathematical operations
+ Addition- Subtraction* Multiplication/ Division% Modulus (remainder)** ExponentiationAssign and update variable values
= Simple assignment+= Add and assign-= Subtract and assign*= Multiply and assign/= Divide and assignCompare values and return boolean
== Equal to (value)=== Strict equal (value & type)!= Not equal to> Greater than< Less thanCombine conditions and logic
&& Logical AND|| Logical OR! Logical NOT// Arithmetic
let sum = 10 + 5; // 15
let power = 2 ** 3; // 8
// Comparison
console.log(5 === "5"); // false (strict)
console.log(5 == "5"); // true (loose)
// Logical
let age = 20;
if (age >= 18 && age < 65) {
console.log("Adult");
}
Handle user interactions with keyboard, mouse, and focus events
An event occurs when a user interacts with a web page. Event handling is the process of specifying actions to be performed when an event occurs.
onkeydown - Key pressed downonkeyup - Key releasedonkeypress - Key pressed & releasedonclick - Mouse clickedonmouseover - Mouse over elementonmouseout - Mouse leaves elementonmousemove - Mouse movesonfocus - Element receives focusonblur - Element loses focusonselect - Text selected// Button click event
document.getElementById('myBtn').onclick = function() {
alert('Button clicked!');
};
// Mouse over event
element.onmouseover = function() {
this.style.color = 'blue';
};
// Keyboard event
document.onkeypress = function(event) {
console.log('Key pressed: ' + event.key);
};
Automate repetitive tasks with for, while, and do...while loops
Best when you know the exact number of iterations
for (let i = 0; i < 5; i++) {
console.log(i);
}
Best when iterations are unknown or dynamic
let i = 0;
while (i < 5) {
console.log(i);
i++;
}
Executes at least once before checking condition
let i = 0;
do {
console.log(i);
i++;
} while (i < 5);
| Feature | for Loop | while Loop | do...while Loop |
|---|---|---|---|
| Best Used When | Exact number of repeats known | Number of repeats unknown | Code must run at least once |
| Check Timing | Before every iteration | Before every iteration | After first iteration |
| Minimum Runs | 0 (if condition false) | 0 (if condition false) | 1 (always runs once) |
Essential JavaScript functions for common tasks
| Function | Description | Example |
|---|---|---|
alert() |
Displays a dialog box with a message | alert("Hello!"); |
confirm() |
Shows dialog with OK and Cancel buttons | confirm("Are you sure?"); |
prompt() |
Accepts user input through a text box | prompt("Enter name:"); |
parseInt() |
Converts string to integer | parseInt("25"); |
parseFloat() |
Converts string to decimal number | parseFloat("10.33"); |
isNaN() |
Checks if value is not a number | isNaN("Hello"); |
eval() |
Evaluates an expression | eval("2+2"); |
// Get user input
let name = prompt("Enter your name:", "Guest");
console.log("Hello, " + name);
// Convert string to number
let age = parseInt("25");
console.log(age + 5); // 30
// Check if value is a number
if (isNaN("abc")) {
console.log("Not a number!");
}
Join thousands of developers learning JavaScript. Star the repo and begin coding today.
Explore on GitHub