Introduction

JavaScript is a lightweight scripting language.

It is used to create dynamic web pages.

let x = 5;
What you should already know

You should understand HTML basics.

You should know basic CSS.

<p>Paragraph</p>
JavaScript and Java

JavaScript is different from Java.

They serve different purposes.

console.log("JavaScript");
Hello World

This is the simplest program.

It prints Hello World.

alert("Hello World");
Variables

Variables store data values.

They can be declared using let, var, or const.

let age = 20;
Declaring variables

Variables must be declared before use.

Use modern keywords like let and const.

const name = "Ali";
Variable scope

Scope determines accessibility.

There are block and function scopes.

function test() { let a = 10; }
Global variables

Global variables are accessible everywhere.

They are declared outside functions.

var globalVar = 100;
Constants

Constants cannot be reassigned.

They are declared using const.

const PI = 3.14;
Data types

JavaScript has several data types.

Primitive and reference types exist.

typeof "Hello";
if else statement

The if statement executes based on condition.

Else handles alternative case.

if (x > 5) { console.log("Greater"); } else { console.log("Smaller"); }
while statement

The while loop repeats code.

It runs while condition is true.

let i = 0; while (i < 3) { i++; }
Function declarations

Functions group reusable code.

They run when called.

function greet(name) { return "Hello " + name; }
Reference

This documentation is for learning purposes.

Inspired by MDN and JavaScript guides.

https://developer.mozilla.org