Javascript
Javascript
Topics Covered : –
1. What is Javascript?
2. Why we need Javascript?
3. History of Javascript
4. JS Engines of different browser
5. Characteristics of Javascript
6. Ways to add Javascript
7. Variables in Javascript
8. Datatypes in Javascript
9. Operators in Javascript
10.Decision-Making Statements in Javascript
WHAT IS JAVASCRIPT
It is the language you can use at browser side as well as server side.
A lot of framework and libraries are based on Javascript. It can be used for both
frontend and backend.
Frontend – React.Js, Angular.Js, Next.Js
Backend – Node.Js, Express.Js
WHY WE USING THE JS?
•Runs inside the browser (Chrome). •No need to define variable types (number,
•No need for a server to process every action. string, etc.).
•Example: Clicking a button changes text •JS automatically detects the type at runtime.
instantly.
•Allows operations between different data types. •Executes line by line in the browser (no need to
•Can cause unexpected behavior. compile).
•Example: (String + Number = String), (String - •Easier to debug but slightly slower than compiled
Number = Number) languages.
CHARACTERISTICS OF JAVASCRIPT
•console.log("First");
•alert("Pause here...");
•console.log("Second"); // Runs only after alert is closed
But JS also supports Asynchronous tasks (like setTimeout & fetch) to handle multiple
things smoothly!
WAYS TO RUN JAVASCRIPT CODE (ENVIRONMENT
SETUP)
WAYS TO ADD JAVASCRIPT TO A WEBPAGE
VARIABLES IN JAVASCRIPT
Q. What is a Variable in
JavaScript?
A variable is like a container that
stores data.
It holds values that can be used and
changed in a program.
1. Number: It is the values which may be integers or decimal. (Ex: 10, 5.5, 3,27, etc)
3. Boolean: It represents true or false values. True means (one-1) and false means (Zero-0).
Operators are predefined symbols which is used to perform some specific tasks.
DECISION-STATEMENTS IN JS
If-else statement: It will runs different true or false. If condition is satisfied then it
will execute the if block or condition is false then it will execute the else block
respectively.
ELSE-IF LADDER STATEMENT
For-Loop: A for loop is used when you know how many times you want the code to
run.
It includes three parts:
1. Initialization
2. Condition
3. Increment/Decrement
WHILE-LOOP
Do-While Loop: A do-while loop is similar to the while loop but it runs at least
once.
FUNCTIONS IN JAVASCRIPT
Function Call Statement: A function call statement is the part of the program
where function is called, meaning the function is executed.
A function call is the action that triggers that block of code.
To call a function, you simply use its function name and followed by parentheses. ()
FUNCTIONS IN JAVASCRIPT
return Keyword: The return keyword is used to send a value from a function back
to the caller.
NOTE: It should be the last statement inside the function after that function
execution will be stopped.
2. ANONYMOUS FUNCTION
1. Implicit Return: If the function has a single statement, you can omit the
return and curly braces {} .
2. Explicit Return: If there are multiple statements, you need to use explicitly and
you have to use curly braces {} mandatory.
4. CALLBACK FUNCTION