History of JavaSript
1. The Birth of JavaScript (1995)
JavaScript was created by Brendan Eich in 1995 while he was working at Netscape.
- Initially named Mocha
- Later renamed to LiveScript
- Finally renamed JavaScript (because Java was very popular at that time, and the name helped in marketing)
Interestingly, the first version of JavaScript was developed in just 10 days.
2. Standardization (1997)
In 1997, JavaScript was standardized by ECMA International under the name ECMAScript (ES).
This ensured that different browsers followed the same core rules and reduced compatibility issues.
Variables in javascript
Variables in JavaScript are used to store data values.
You can think of a variable as a container that holds information.
How to Declare Variables
In JavaScript, there are three ways to declare variables:
1.Var(Old Method)
`var name = "Hari";
`
Function-scoped
Can be re-declared
Not recommended in modern JavaScript
2.let(Modern & Recommended)
`let age = 22;
`
Block-scoped
Can be updated
Cannot be re-declared in the same scope
3.const(Constant Value)
`const country = "India";
`
Block-scoped
Cannot be updated
Cannot be re-declared
Rules for Naming Variables
Must start with a letter, _, or $
Cannot start with a number
Case-sensitive (name and Name are different)
Avoid reserved keywords (like if, for, while)
Datatypes in javascript
In JavaScript, data types define the type of value a variable can hold
JavaScript has two main categories of data types:
1.Primitive Datatype
2. Non Primitive Datatype
1.Primitive Datatype
Primitive data types are basic data types that store a single value directly in memory
They are immutable, meaning their value cannot be changed once created (a new value is created instead).
1.Number
Represents both integers and decimal values.
`let age = 21;
let price = 105.234;
`
2.String
Represents text (written inside quotes).
`let name = "Hari";
let message = 'Hello World';
`
3.Boolean
Represents true or false values.
`let isLoggedIn = true;
let isAdmin = false;
`
4.Undefined
A variable that is declared but not assigned a value.
`let x;
console.log(x); // undefined
`
5.Null
Represents an intentional empty value.
`let data = null;
`
6.BigInt
Used for very large numbers.
`let bigNumber = 123456789012345678901234567890n;
`
7.Symbol
Used to create unique identifiers (mostly used in advanced concepts).
`let id = Symbol("unique");
`
2.Non Primitive Datatype
Non-primitive data types (also called reference data types) store collections of values or complex data
They are stored as references (memory addresses) instead of storing the actual value directly
They are mutable, meaning their contents can be changed.
1.Object
Stores data in key–value pairs.
`let person = {
name: "Hari",
age: 21
};
`
2.Array
Used to store multiple values in a single variable.
`let numbers = [1, 2, 3, 4];
`
3.Function
Functions are also treated as objects in JavaScript.
`function greet() {
console.log("Hello!");
}
`
Top comments (1)
Awesome blog Very beginner-friendly explanation.
I have question:
Can you explain the difference between null and undefined in more detail?
How does JavaScript handle memory for primitive vs reference types?
Can you explain more about Symbol and where it is used in real applications?
Why are functions treated as objects in JavaScript?
What are some common mistakes beginners make while using var, let, and const?
Since JavaScript was created in 10 days, why is it so powerful today? What made it evolve so much?
What are the next important topics beginners should learn after variables and data types?
Can you write the next blog about scope and hoisting in detail?
EXPLAIN ALL QUESTION.