What is JavaScript?
JavaScript is the programming language of the Web. It makes web pages interactive and dynamic by:
- Updating and changing both HTML and CSS.
- Calculating, manipulating, and validating data.
- Calculating, manipulating, and validating data.
Responding to user events like clicks, scrolls, and inputs.
JavaScript Syntax Basics
JavaScript syntax defines rules for how programs are constructed.
Variable Declaration:
var x;
let y;
x = 5;
y = 6;
let z = x + y;
JavaScript Values
JavaScript syntax defines two types of values:
Fixed values → called Literals
Example: 5, "Hello", true
Variable values → stored in Variables
Example: let name = "Swetha"
JavaScript Comments
Comments are used to explain code and prevent it from running.
➤ Single-Line Comment:
// This is a comment
➤ Multi-Line Comment:
/* This is a
multi-line comment */
JavaScript Variables
Variables are containers for storing data.
You can declare variables in 4 ways:
Automatically (not recommended)
Using **var** – old way
Using **let** – modern, block-scoped
Using **const** – block-scoped & constant
let in JavaScript
Key Features of let:
- Block Scope
- Must be declared before use
- Cannot be redeclared in the same scope
{
let x = 2;
}
// x is not accessible here – it’s block scoped
const in JavaScript
The const keyword is also introduced in ES6 (2015).
** Key Features of const:**
- Block Scope
- Cannot be Redeclared
- Cannot be Reassigned
const pi = 3.14;
pi = 3.14159; // ❌ Error: Assignment to constant variable
Use const for variables that should never change.
JavaScript is a powerful tool for web development. In just one day, you can:
- Learn how to declare variables
- Understand data types
- Add comments to explain your code
- Use let and const effectively
Top comments (0)