JavaScript
JavaScript
JavaScript is a lightweight, interpreted programming language.
It is used to add behavior to HTML and CSS.
It runs in the browser (client-side).
JavaScript is one of the core technologies of the web
What JS can do?
Add interactivity to websites
Manipulates HTML and CSS
Handle events (click, keypress, etc)
Fetch data from APIs
Validate forms and user input
And many more..
Features
Cross-platform (runs on all major browser)
Lightweight (easy to learn)
Versatile (Used for frontend)
Hight performance (fast execution in the browser)
Huge community (large ecosystem and support)
Data types
JavaScript provides different data types to hold different types of values. There are two types of data types in JavaScript.
a) Primitive Datatype
b) Non-primitive data type
1. Primitive data type:
Primitive data types can hold one single value at a time. There are five types of primitives in JavaScript. They are as follows:
String = Represents a sequence of characters e.g “hello”
Numbers = Represents numeric values e.g 100
Boolean = Represents Boolean value e.g True and False
Undefined = Represents an undefined value
Null = Represents null i.e. no value at all
2. Non-primitive (Reference type) data types:
Non-primitive data types can hold collections of values (multiple values) and more complex entities. The non-primitive datatypes are as follows:
Object =Represents an instance through which we can access members
Array = represent a group of similar values
RegExp = Represents a regular expression
Variables
There are 3 ways to declare variables in JavaScript: let, var, const
1. Let
Value can be updated
Cannot be redeclared in the same scope
Use when value can change
Modern designer uses let variable mostly
2. Var
Value can be updated
Can be redeclared
Not recommended in modern JS
3. Const
Cannot be reassigned
Use for constant value
JavaScript is a lightweight, interpreted programming language.
It is used to add behavior to HTML and CSS.
It runs in the browser (client-side).
JavaScript is one of the core technologies of the web
What JS can do?
Add interactivity to websites
Manipulates HTML and CSS
Handle events (click, keypress, etc)
Fetch data from APIs
Validate forms and user input
And many more..
Features
Cross-platform (runs on all major browser)
Lightweight (easy to learn)
Versatile (Used for frontend)
Hight performance (fast execution in the browser)
Huge community (large ecosystem and support)
Data types
JavaScript provides different data types to hold different types of values. There are two types of data types in JavaScript.
a) Primitive Datatype
b) Non-primitive data type
1. Primitive data type:
Primitive data types can hold one single value at a time. There are five types of primitives in JavaScript. They are as follows:
String = Represents a sequence of characters e.g “hello”
Numbers = Represents numeric values e.g 100
Boolean = Represents Boolean value e.g True and False
Undefined = Represents an undefined value
Null = Represents null i.e. no value at all
2. Non-primitive (Reference type) data types:
Non-primitive data types can hold collections of values (multiple values) and more complex entities. The non-primitive datatypes are as follows:
Object =Represents an instance through which we can access members
Array = represent a group of similar values
RegExp = Represents a regular expression
Variables
There are 3 ways to declare variables in JavaScript: let, var, const
1. Let
Value can be updated
Cannot be redeclared in the same scope
Use when value can change
Modern designer uses let variable mostly
2. Var
Value can be updated
Can be redeclared
Not recommended in modern JS
3. Const
Cannot be reassigned
Use for constant value