JavaScript is a lightweight scripting language.
It is used to create dynamic web pages.
let x = 5;
- Client-side
- Interpreted
- Dynamic
You should understand HTML basics.
You should know basic CSS.
<p>Paragraph</p>
- HTML
- CSS
- Basic programming
JavaScript is different from Java.
They serve different purposes.
console.log("JavaScript");
- Java is compiled
- JS is interpreted
- Different syntax
This is the simplest program.
It prints Hello World.
alert("Hello World");
- First example
- Simple output
- Easy syntax
Variables store data values.
They can be declared using let, var, or const.
let age = 20;
- let
- var
- const
Variables must be declared before use.
Use modern keywords like let and const.
const name = "Ali";
- Declaration
- Initialization
- Assignment
Scope determines accessibility.
There are block and function scopes.
function test() {
let a = 10;
}
- Local scope
- Block scope
- Function scope
Global variables are accessible everywhere.
They are declared outside functions.
var globalVar = 100;
- Accessible globally
- Risk of conflicts
- Stored in window object
Constants cannot be reassigned.
They are declared using const.
const PI = 3.14;
- Immutable reference
- Block scoped
- Must initialize
JavaScript has several data types.
Primitive and reference types exist.
typeof "Hello";
- String
- Number
- Boolean
The if statement executes based on condition.
Else handles alternative case.
if (x > 5) {
console.log("Greater");
} else {
console.log("Smaller");
}
- Conditional logic
- Comparison
- Decision making
The while loop repeats code.
It runs while condition is true.
let i = 0;
while (i < 3) {
i++;
}
- Loop
- Repetition
- Condition check
Functions group reusable code.
They run when called.
function greet(name) {
return "Hello " + name;
}
- Reusable
- Parameters
- Return values
This documentation is for learning purposes.
Inspired by MDN and JavaScript guides.
https://developer.mozilla.org
- MDN
- FreeCodeCamp
- W3Schools