JavaScript Notes
JavaScript Notes
JavaScript Notes
Output
Operators
• There are 8 kind of operators in java script.
Which are ----
1. Assignment Operators
2. ArithMetic Operators .
3. Comparision Operators .
4. Logical Operators .
5. String Operators .
6. Unary Operators .
7. Ternary Operators .
8. Type Operators .
Example:
Output:
7H 23M 57S Page 4
Output:
Output:
Output:
Output:
Logical Operator :
First watch a Example and try to understand how
7H 23M 57S Page 5
First watch a Example and try to understand how
it works.
OUTPUT:
Logical NOT:
Returns True if the oprands is false, and false if
the operand is true.
Q1. Write a Programme that determines if a
person is eligible to drive based on their age
greater than or equal to 18 and having a valid
Driving License ?
CODE:
OUTPUT:
• Ternary(conditional) Operator :
1. Syntax : Condition? expressionIfTrue :
expressionIfFalse
7H 23M 57S Page 6
expressionIfFalse
Q. !! Write a programme to check if the
candidates isEligibleForDrive or Not?
**age must be equal or greater than 18.
Question Summary : actually we need to use
ternary or conditional operators instead of using
if-else statement.
code:
OUTPUT:
Q. Let say you have a variable score representing
a student's exam score. If the score is greater
than or equal to 60, the student passes;
otherwise they fail. Use the ternary operator to
determine the result and store it in variable called
result. Log the result to the console.
CODE:
Eg.1
Interview Question
Project Materials :
• if the person is 18 years older, a citizen, and
registered to vote, display a massage saying
they are eligible to vote.
• if the person is younger than 18, not a citizen,
7H 23M 57S Page 7
• if the person is younger than 18, not a citizen,
not registered to vote, display a massage
saying they are not eligible for vote .
• if the person is 18 or older bot not a citizen,
display a massage they are not eligible due to
citizenship status.
• if the person is 18 years older and a citizen bit
not registered to vote, show a massage saying
you are not eligible due to registration status.
• extend voting eligibility checker with
additional conditions.
CODE:
================================
Switch Statement :
================================
Switch Statement: The switch statement is used
to perform different actions based on different
conditions.
Important Question :
Write a java Script switch statement that takes a
variable areaOfShape representing different
shape, and based on its value, calculating and log
the area of the corresponding shape. consider the
three shapes : 'rectangle, 'circle', and 'square'. For
rectangle use variable a & b the sides; for circle
use a variable r as the radius; and for square use
variable as the side length. If the provided shape
is not recognized, log a massage saying, "Sorry,
The shape is not available." Test your switch
statement with areaOfShape set to Square and
sides a and b set to 5 and 10, Respectively. Ensure
that the correct area (25 in this case.) is logged to
Output:
================================
While-Loop:
================================
While-Loop:
A while loop in JavaScript is a control structure
that repeatedly executes a block of code as long
as specified conditions remains true. The loop
continues iterating while the condition is true.
And it terminates when the condition becomes
false.
Q.
Write the Syntax of While-loop.
Syntax:
While-Loop Eg1 :
-: JavaScript Functions :-
Syntax:
Eg1:
-: Function Declaration :-
-: Function Invocation :-
=> It is nothing but calling any function is called
function invocation.
On previous image the line ---
console.log(greet()); is called function invocation.
-: Function Parameter :-
-: Function Argument :-
Practice Time :
Q. Write javaScript programme that defines a
function called greet to welcome individual to the
Thapa Technical JS Course. The function should
7H 23M 57S Page 12
Thapa Technical JS Course. The function should
take a name parameter and output the massage
"Hello [Name], Welcome to Thapa Technical JS
Course." Call the function twice, Once with the
first argument "Vinod" and once with the
argument "Ram".
-: Function Expression :-
Function Expression :- Function Expression is a
way to define a function as a part of an
expression. It can be either named or
anonymous.. If it's named , it becomes a names
function expression.
-: Anonymous Function :-
Anonymous Function :- An anonymous function is
a function without a name. It can be created
using either a function or a function declaration
without a specified name.
-: Return Keyword :-
Return Keyword :- In JavaScript, The return
statement is used with in a function to specify the
value that he function should produce or provide
back to the code called it. The return statement
stops the execution of a function and sends a
value back to the caller.
-: EcmaScript Timeline :-
2015 EcmaScript
Let :- The let keyword is used to declare variable
with block scope. Variable declared with let are
mutable, meaning their values can be reassigned.
Const :- The const keyword is used to declare
variable with block scope, but once the value is
assigned to a const variable, it cannot be
reassigned. Const variable are immutable.
Slice()
-: JavaScript Arrays :-
-: Creating Array :-
-: Array Constructor :-
Code :-
Output :-
-: Array Literal :-
Eg:-
Output :
Output :
Eg1 :
Output :
Output :-
-: Searchhing in arrays :-
7H 23M 57S Page 18
-: Searchhing in arrays :-
IndexOf method : The indexOf method returns
the first index at which a given element can be
found in Array. And if it can't find the element it
will return -1;
Code :
Output :
Output :
Output :
Practice Question :-
Q.
-: Search - Filter :-
• The find() Method is used to find the first
element in an Array that satisfies a provided
testing function. it returns the first matching
element or undefined is no element is found.
-----------------------------------------------------
Sorting In Array Objects
-----------------------------------------------------
Sorting an Array : The sort method sorts the
elements of an Array in place in returns the
sorted Array defaults, it sorts element as string.
7H 23M 57S Page 20
sorted Array defaults, it sorts element as string.
Output:
-----------------------------------------------------
-: String :-
-----------------------------------------------------
String And its Properties Escape Charecters
String Search Method Extracting String Parts
Extracting String Replace String
Charecters Charecters
Other Useful Methods
Q. What is a String ?
Ans: String in JavaScript are fundamental data
type that represents a sequence of characters.
-: Escape Characters :-
Output:-
Output:-
Code:-
Code :
Output :
Code:
Output:
Ans:
Code :
Output :
________________________________________
Code :
Code:
Output :
Code:
Code:
Output: