[Go to site: main page, start]

0% found this document useful (0 votes)
2 views30 pages

Java Script

JavaScript is a high-level, dynamic scripting language used for web development, enabling both client-side and server-side programming. Client-side JavaScript runs in the user's browser for interactive web pages, while server-side JavaScript, facilitated by Node.js, handles backend logic and database interactions. The document also covers JavaScript's core features, data types, and variable handling, emphasizing its versatility and importance in modern web technologies.

Uploaded by

pummyash2001
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views30 pages

Java Script

JavaScript is a high-level, dynamic scripting language used for web development, enabling both client-side and server-side programming. Client-side JavaScript runs in the user's browser for interactive web pages, while server-side JavaScript, facilitated by Node.js, handles backend logic and database interactions. The document also covers JavaScript's core features, data types, and variable handling, emphasizing its versatility and importance in modern web technologies.

Uploaded by

pummyash2001
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

What is JavaScript?

(Client-side vs Server-side)

JavaScript is one of the most essential and widely used programming languages in the world
of web development. From creating interactive websites to building scalable backend
services, JavaScript plays a crucial role across the full spectrum of web technologies.

In this article, you’ll learn what JavaScript is, explore the difference between client-side and
server-side JavaScript, and discover when and why you should use each.

What is JavaScript?

JavaScript is a high-level, dynamic scripting language initially developed by Brendan Eich in


1995 for Netscape Navigator. Originally designed for basic web page interactions, it has
developed into a robust full-stack programming language that can be used on the server as
well as in the browser.

Unlike HTML and CSS, which define structure and style, JavaScript adds behavior and
interactivity to web pages. It's:

1. Lightweight and interpreted

2. Event-driven

3. Prototype-based (object-oriented)

4. Supported by all modern browsers

Let’s quickly look at the “Client-side and Server-side aspects of JavaScript, alongside their
common uses, benefits, and limitations.”

JavaScript on the Client-side:

What is Client-side JavaScript?

Client-side JavaScript is the version of the language that runs in the user's browser. It’s
responsible for making web pages dynamic and interactive without requiring page reloads or
server requests.

Common Uses:
 Updating content without refreshing (AJAX)

 Handling user input through forms

 Animations and sliders

 DOM manipulation (adding/removing HTML elements)

 Responding to mouse clicks or keyboard events

Benefits:

 Fast performance (runs on the user’s device)

 Reduced server load ( less need for server processing)

 Enhanced user experience ( more interactive interfaces)

Limitations:

 Limited access to file systems or OS-level operations

 Depends on the user's browser and device capabilities

 Can expose sensitive logic to users (security concerns)

JavaScript on the Server-side:

What is Server-side JavaScript?

Server-side JavaScript runs on a web server instead of in the browser. This became possible
with the rise of [Link], a powerful JavaScript runtime built on Chrome’s V8 engine,
introduced in 2009.

Common Uses:

 Handling HTTP requests and responses

 Connecting to databases (e.g., MongoDB, MySQL)

 Building REST APIs

 Managing server-side logic and authentication

Benefits:

 A quick access to server resources (databases, file system)

 Unified language for both front-end and back-end

 High scalability with event-driven architecture

Limitations:

 Server resource consumption


 Requires backend infrastructure setup

 Concurrency and error handling can be complex

Here, we'll look at the Key difference between Client-side and Server-side.

Client-side vs Server-side JavaScript: Key Differences

S/
Client-side JavaScript Server-sides JavaScript
N

1 Runs in the user's browser. Runs on the web server (e.g., [Link])

Controls the user interface, handles Handles backend logic, APIs, databases,
2
browser interactions. and authentication.

Code is visible to users (can be Hidden from users (executed on the


3
inspected in DevTools) server)

JavaScript with HTML/CSS runs in JavaScript with [Link], [Link],


4
Chrome, Firefox, and Safari. databases, etc.

Here, we will look at when to use either of the two sides (Client-side or Server-side
JavaScript)

Core Features of JavaScript

JavaScript is a high-level, object-based, interpreted scripting language mainly used to create


dynamic, interactive, and intelligent web pages. Its core features make it one of the most
powerful and widely used programming languages.

1. Interpreted Language

JavaScript is executed line-by-line by the browser without any compilation.

How it works:

 The browser reads JavaScript code.

 Converts it into machine instructions.

 Executes it immediately.

Advantages:

 Easy to test and debug

 Faster development
 No compilation step

Example:

alert("Welcome to JavaScript");

2. Dynamically Typed

In JavaScript, we do not need to declare data types.

Example:

let x = 10; // number


x = "Hello"; // now string

This makes coding flexible and easy.

3. Object-Based Language

JavaScript uses objects to represent real-world entities like:

 window

 document

 form

 button

Example:

[Link] = "blue";

4. Event-Driven Programming

JavaScript executes code when an event happens.

Events:

 click

 keypress

 mouseover

 submit

Example:

<button > 5. Client-Side Execution

JavaScript runs on the user’s browser, not on the server.

This means:

 Faster response

 Less server load

 Instant output

Example:
Form validation using JavaScript.

6. Supports Functions

Functions allow code reusability.

Example:

function greet(){
alert("Welcome");
}
greet();

7. Supports DOM Manipulation

JavaScript can change HTML & CSS at runtime.

Example:

[Link]("demo").innerHTML = "Hello";

8. Asynchronous Programming

JavaScript can run background tasks without stopping the page.

Used for:

 API calls

 Data loading

 Live updates

Example:

setTimeout(() => {
alert("Hi");
}, 2000);
9. Cross-Platform Support

JavaScript works on:

 Windows

 Linux

 Android

 iOS

 All browsers

10. Secure Execution

JavaScript runs in a browser sandbox, so it cannot access system files.

This protects the user’s computer.

What is a Variable?

A variable is like a box where you can store data or a reference to data.

In a math equation, when we say x = 1 it means, "anywhere you see x, you should replace it
with 1". In this case, x is a variable, while 1 is the value of it. That is: x points to 1.

This means that without x, there will be no reference to 1. There could be other occurrences
of 1 in the equation but those will be different than the 1 which x was referring to. For
example:

/* The code below means x is 1

* So during execution, anywhere x appears after the line below,

* the complier replace x with 1.

*/

let x = 1;

let y = 1; // the value which y refers to is different from that of x

[Link](x); // This line will log 1 to the console.

In the code snippet above, x refers to the value 1, and y It also refers to another value 1, but
note that both values are distinct, just like you can have two different brands of bottled
water even though they both contain water.

So, when we mention the variable name x, we get the value assigned to that variable.

How to Declare a Variable


let score;

The program above declares/creates a variable called score.

In JavaScript, creating variables is that simple. The type of the variable is the type of the
value stored in it. That is, if the variable score holds a value of 1, the type for
the score variable is number. So we can say, score is a number variable.

To create a variable, we have to do the following;

1. Declare the variable using one of these keywords: let, const or var.

2. Determine a name to call the variable and write it on the same line as the keyword
used in step 1.

let score; // creates variable 'score'

Notice that this time, we did not give it a value. We just simply created a container that will
store something. For now, it is empty. Although it has no content at the moment, we'll surely
provide content for it.

Variable Assignment and Initialization

We can assign a value to a variable by using the assignment (=) operator—the variable name
to the left of it, and the value to the right.

score = 1;

The code snipped above assigns 1 as the value of score (this is called variable assignment).

When we combine variable declaration and assignment in one operation, it is called variable
initialization.

let score = 1;

As seen above, we declare the variable score, and immediately on the same line, assign the
value 1 to it.

This means that we provided an initial value for the variable when it was created.

How to Call a Variable

If you want to use a variable for an operation at any time in your program, you can simply
just "call" it. To call a variable is the same as mentioning or using it.

[Link](score + 1) // 2

In the code snippet above, the variable score was used in the line of code. Therefore, It will
be replaced with its actual value 1 during the code execution. This means we'd have 1 +
1 executed, resulting in 2.
In the next section, let's learn how to properly name our variables in other to ensure our
codes are neat and readable.

How to Name Variables

Just like naming a human or pet or labeling an object, we always put in much thought to
ensure that the name tells a story and gives an idea of how we feel about the role of that
pet, human, or object.

JavaScript is somewhat liberal when it comes to how variable naming can be done and also
how long it could be.

For example, pneumonoultramicroscopicsilicovolcanoconiosis is a valid variable name in


JavaScript even though it is long.

It is generally a good practice to give meaningful names to variables and they should be of a
reasonable length.

Let your variables be simple and contextual. For


example: author, publishedDate, readTime, shouldCompress, and so on.

It should be self-explanatory. Just avoid cryptic names where possible.

JavaScript Data Types

Data types in JavaScript referes to the types of the values that we are storing or working
with. One of the most fundamental characteristics of a programming language is the set
of data types it supports. These are the type of values that can be represented and
manipulated in a programming language.

JavaScript data types can be categorized as primitive and non-primitive (object). JavaScript
(ES6 and higher) allows you to work with seven primitive data types −

 Strings of text e.g. "This text string" etc.

 Numbers, eg. 123, 120.50 etc.

 Boolean e.g. true or false.

 null

 undefined

 BigInt

 Symbol

BigInt and Symbol are introduced in ES6. In ES5, there were only five primitive data types.

In addition to these primitive data types, JavaScript supports a composite data type known
as object.
The Object data type contains the 3 sub-data types −

 Object

 Array

 Date

Why are data types important?

In any programming language, data types are important for operation manipulation.

For example, the below code generates the 1010 output.

let sum = "10" + 10;

Here, the JavaScript engine converts the second operand to a string and combines it using
the '+' operator rather than adding them.

So, you need to ensure that the type of operands is correct.

Now, let's learn about each data type with examples.

JavaScript String

In JavaScript, the string is a sequence of characters and can be created using 3 different ways
given below −

 Using the single quote

 Using the double quote

 Using the backticks

Example

In the example below, we have created strings using single quotes, double quotes, and
backticks. In the output, it prints the same result for all 3 strings.

<html>

<head>

<title> JavaScript string </title>

</head>

<body>

<script>

let str1 = "Hello World!"; // Using double quotes

let str2 = 'Hello World!'; // Using single quotes


let str3 = `Hello World!`; // Using backtick

</script>

</body>

</html>

JavaScript Number

A JavaScript number is always stored as a floating-point value (decimal number).

JavaScript does not make a distinction between integer values and floating-point values.

JavaScript represents numbers using the 64-bit floating-point format defined by the IEEE 754
standard.

Example

In the example below, we demonstrate JavaScript numbers with and without decimal points.

<html>

<head>

<title> JavaScript number </title>

</head>

<body>

<script>

let num1 = 10; // Integer

let num2 = 10.22; // Floating point number

[Link]("The value of num1 is " + num1 + "<br/>");

[Link]("The value of num2 is " + num2);

</script>

</body>

</html>

JavaScript Boolean

In JavaScript, the Boolean data type has only two values: true or false.

<html>

<head>
<title> JavaScript Boolean </title>

</head>

<body>

<script>

let bool1 = true;

let bool2 = false;

[Link]("The value of the bool1 is " + bool1 + "<br/>");

[Link]("The value of the bool2 is " + bool2 + "<br/>");

</script>

</body>

</html>

JavaScript Undefined

When you declare a variable but don't initialize it, it contains an undefined value. However,
you can manually assign an undefined value to the variable also.

<html>

<head>

<title> JavaScript Undefined </title>

</head>

<body>

<script>

let houseNo; // Contains undefined value

let apartment = "Ajay";

apartment = undefined; // Assigning the undefined value

[Link]("The value of the house No is: " + houseNo + "<br/>");

[Link]("The value of the apartment is: " + apartment + "<br/>");

</script>

</body>

</html>
JavaScript Null

When any variable's value is unknown, you can use the null. It is good practice to use
the null for the empty or unknown value rather than the undefined one.

<html>

<head>

<title> JavaScript null </title>

</head>

<body>

<script>

let houseNo = null; // Unknown house number

let apartment = "B-2";

appartment = null; // Updating the value to null

[Link]("The value of the houseNo is: " + houseNo + "<br/>");

[Link]("The value of the apartment is: " + apartment + "<br/>");

</script>

</body>

</html>

JavaScript Bigint

JavaScript stores only 64-bit long floating point numbers. If you want to store a very large
number, you should use the Bigint. You can create Bigint by appending n to the end of the
number.

<html>

<head>

<title> JavaScript Bigint </title>

</head>

<body>

<script>

let largeNum = 1245646564515635412348923448234842842343546576876789n;


[Link]("The value of the largeNum is " + largeNum + "<br/>");

</script>

</body>

</html>

JavaScript Symbol

The Symbol data type is introduced in the ES6 version of JavaScript. It is used to create
unique primitive, and immutable values.

The Symbol() constructor can be used to create a unique symbol, and you may pass the
string as a parameter of the Symbol() constructor.

Example

In the example below, we created the sym1 and sym2 symbols for the same string. After
that, we compared the value of sym1 and sym2, and it gave a false output. It means both
symbols are unique.

<html>

<head>

<title> JavaScript Symbol </title>

</head>

<body>

<script>

let sym1 = Symbol("123");

let sym2 = Symbol("123");

let res = sym1 === sym2;

[Link]("Is sym1 and Sym2 are same? " + res + "<br/>");

</script>

</body>

</html>

Non -Primitive Datatypes:

1. Object

JavaScript objects are key-value pairs used to store data, created with {} or the new
keyword. They are fundamental as nearly everything in JavaScript is an object.
let gfg = {

type: "Company",

location: "Noida"

[Link]([Link])

2. Arrays

An Array is a special kind of object used to store an ordered collection of values, which can
be of any data type.

let a1 = [1, 2, 3, 4, 5];

[Link](a1);

let a2 = [1, "two", { name: "Object" }, [3, 4, 5]];

[Link](a2);

3. Function

A function in JavaScript is a block of reusable code designed to perform a specific task


when called.

// Defining a function to greet a user

function greet(name) { return "Hello, " + name + "!"; }

// Calling the function

[Link](greet("Ajay"));

4. Date Object

The Date object in JavaScript is used to work with dates and times, allowing for date
creation, manipulation, and formatting.

// Creating a new Date object for the

// current date and time

let currentDate = new Date();

// Displaying the current date and time

[Link](currentDate);
JavaScript Operators

Definition

JavaScript Operators are special symbols or keywords that are used to perform operations
on one or more operands (values or variables) to produce a result. They are fundamental in
forming expressions, performing calculations, and controlling program logic.

1. Arithmetic Operators

Definition:
Arithmetic operators are used to perform basic mathematical operations such as addition,
subtraction, multiplication, division, and modulus on numerical values.

Example:

let a = 10, b = 5;
[Link](a + b); // 15

2. Assignment Operators

Definition:
Assignment operators are used to assign values to variables. They can also combine
arithmetic operations with assignment to simplify expressions.

Example:

let x = 10;
x += 5; // 15

3. Comparison Operators

Definition:
Comparison operators are used to compare two values or expressions and return a Boolean
result (true or false) based on the comparison.

Example:

[Link](10 > 5); // true

4. Logical Operators

Definition:
Logical operators are used to combine or modify Boolean expressions. They are mainly used
in decision-making statements such as if-else conditions.

Example:

[Link](true && false); // false

5. Bitwise Operators
Definition:
Bitwise operators are used to perform operations on binary (bit-level) representations of
numbers. These operations are carried out bit by bit.

Example:

[Link](5 & 1); // 1

6. Ternary Operator

Definition:
The ternary operator is a conditional operator that provides a shorthand way of writing
simple if-else statements using three operands.

Example:

let result = (age >= 18) ? "Adult" : "Minor";

7. Comma Operator

Definition:
The comma operator is used to evaluate multiple expressions in a single statement, from left
to right, and returns the value of the last expression.

Example:

let result = (1, 2, 3); // 3

8. Unary Operators

Definition:
Unary operators are operators that operate on a single operand to perform operations such
as incrementing, decrementing, or determining the type of a variable.

Example:

let x = 5;
++x; // 6

9. Relational Operators

Definition:
Relational operators are used to check the relationship between two operands, such as
whether a property exists in an object or whether an object belongs to a specific class or
type.

Example:

[Link]("length" in {length:10}); // true

10. BigInt Operators


Definition:
BigInt operators are used to perform arithmetic operations on very large integer values that
are beyond the safe limit of regular JavaScript numbers.

Example:

let a = 12345678901234567890n;
let b = 10n;
[Link](a + b);

What Are Expressions?#

An expression is code that evaluates to a value. Unlike declarations, expressions “return”


something—even if it’s undefined (e.g., x = 5 evaluates to 5).

Expressions can be nested inside other expressions or statements, making them flexible
building blocks of code.

Types of Expressions#

1. Arithmetic Expressions#

Evaluate to a number:

2 + 3; // 5 (expression) 10 / 2 * 5; // 25 (expression)

2. String Expressions#

Evaluate to a string:

"Hello" + " " + "World"; // "Hello World" (expression) `Name: ${name}`; // Template literal
(expression, evaluates to string)

3. Logical Expressions#

Evaluate to true or false (or a truthy/falsy value):

5 > 3; // true (expression) isLoggedIn && "Welcome"; // "Welcome" (if isLoggedIn is true)

4. Assignment Expressions#

Evaluate to the assigned value:

let x; x = 10; // Expression (evaluates to 10) x += 5; // 15 (expression, same as x = x + 5)

5. Function Expressions#

Define functions as values (anonymous or named). They are not hoisted, so you can’t call
them before declaration.

// Anonymous function expression (assigned to variable) const add = function(a, b)


{ return a + b; }; // Named function expression (name is only visible inside the function)
const multiply = function multiply(a, b) { return a * b; }; add(2, 3); // 5 (works, since
expression is assigned before use)

6. Arrow Function Expressions#

Shorthand for function expressions:

const square = (num) => num * num; // Arrow function expression square(4); // 16

7. Object/Array Literals#

Evaluate to objects or arrays:

{ name: "Alice", age: 30 }; // Object literal (expression, evaluates to object) [1, 2, 3]; // Array
literal (expression, evaluates to array)

8. Ternary Operator (Conditional Expression)#

Evaluate to one of two values based on a condition:

const isAdult = age >= 18 ? "Adult" : "Minor"; // Expression

Definition:

A statement in JavaScript is a complete instruction that tells the program to perform a


specific action.
A JavaScript program is made up of multiple statements executed in sequence.

Types of Statements

1. Conditional Statements – Used for decision making

2. Looping Statements – Used to repeat code

3. Jumping Statements – Used to control flow (break, continue, return)

Conditional Statements in JavaScript

Definition:

Conditional statements are used to make decisions in a program.


They execute different blocks of code depending on whether a condition is true or false.

Types of Conditional Statements

if Statement

Definition:

The if statement checks a condition. If it is true, the block of code inside { } is executed.

Syntax:
if (condition) {
// code
}

Example:

let x = 20;

if (x % 2 === 0) {
[Link]("Even");
}

if-else Statement

Definition:

The if-else statement executes one block if the condition is true and another block if it is
false.

Syntax:

if (condition) {
// true block
} else {
// false block
}

Example:

let age = 25;

if (age >= 18) {


[Link]("Adult");
} else {
[Link]("Not Adult");
}

3️⃣ else if Statement

🔸 Definition:

Used to check multiple conditions. The first true condition block is executed.

🔸 Syntax:

if (condition1) {
} else if (condition2) {
} else {
}

🔸 Example:

let x = 0;

if (x > 0) {
[Link]("Positive");
} else if (x < 0) {
[Link]("Negative");
} else {
[Link]("Zero");
}

switch Statement

Definition:

The switch statement checks a variable against multiple values and executes the matching
case.

Syntax:

switch(expression) {
case value1:
// code
break;
case value2:
// code
break;
default:
// code
}

Example:

let day = 2;

switch(day) {
case 1:
[Link]("Monday");
break;
case 2:
[Link]("Tuesday");
break;
default:
[Link]("Other day");
}

Ternary Operator ( ?: )

Definition:

A short form of if-else that uses three operands.

Syntax:

condition ? value1 : value2;

Example:

let age = 21;

let result = (age >= 18) ? "Eligible" : "Not Eligible";


[Link](result);

Nested if...else

Definition:

An if or else statement inside another if or else is called nested if.

satisfied. They help reduce repetition and make programs more efficient and organized.

 Loops continue running until the condition becomes false.

 They are useful for iterating over arrays, strings, and ranges of values.
for LOOP

The FORLOOP repeats a block of code a specific number of times. It contains initialization,
condition, and increment/decrement in one line.

Used when you know how many times to repeat.


Syntax:
for(initialization; condition; increment/decrement) {
// code
}
Example:
for (let i = 1; i <= 5; i++) {
[Link](i);
}
while Loop

The while loop executes as long as the condition is true. It can be thought of as a repeating if
statement. (Used when you don’t know exact number of repetitions.)

Syntax
while (condition) {
// Code to execute
}

Example:

let i = 1;

while (i <= 5) {

[Link](i);

i++;

do-while Loop

The do-while loop is similar to while loop except it executes the code block at least once
before checking the condition.

(Runs at least one time, even if condition is false.)

Syntax:

do {
// code
} while(condition);

Example:

let i = 1;

do {
[Link](i);
i++;
} while (i <= 5);

Jumping Statements in JavaScript

Jumping statements are used to control the flow of a loop or block of code by stopping,
skipping, or transferring execution to another part of the program.

Jumping statements are 2 [Link] are:

[Link] Statement

[Link] Statement

The break Statement


The break statement is used to exit a loop when a certain condition is satisfied. It is
commonly used when searching for a specific value in an array or when an early exit from a
loop is required.

for (let i = 1; i <= 5; i++) {

if (i == 3) {

break;

[Link](i);

continue Statement

The continue statement is used to skip the current iteration and move to the next iteration
of the loop.

for (let i = 1; i <= 5; i++) {

if (i == 3) {

continue;

[Link](i);

Example:

let weather = "sunny";


let temp = 25;

if (weather === "sunny") {


if (temp > 30) {
[Link]("Hot day");
} else {
[Link]("Pleasant day");
}
}

Functions in JavaScript

Definition:
A function in JavaScript is a reusable block of code that is used to perform a specific task.
It executes only when it is called or invoked and helps in reducing code repetition and
improving program structure.

Simple Example (Creation and Calling)

✔ Function Creation:

function greet() {
[Link]("Hello Students");
}

✔ Function Calling:

greet();

Output:
Hello Students

Types of Functions (Based on Arguments and Return Value)

Function with No Arguments and No Return Value

Definition:

A function that does not take any input (arguments) and does not return any value. It only
performs a task.

Example:

function display() {
[Link]("Welcome");
}

display();

Function with Arguments and No Return Value

Definition:

A function that takes input values (arguments) but does not return any value.

Example:

function show(name) {
[Link]("Hello " + name);
}

show("Akhila");

Function with No Arguments and Return Value


Definition:

A function that does not take any input, but returns a value.

Example:

function getNumber() {
return 10;
}

[Link](getNumber());

Function with Arguments and Return Value

Definition:

A function that takes input values and returns a result.

Example:

function add(a, b) {
return a + b;
}

[Link](add(2, 3));

let s1 = new Student("Akhila", 20);

Objects in JavaScript

Definition:

An object in JavaScript is a dynamic data structure used to store related data in the form of
key-value pairs.
Each key (also called a property) uniquely identifies its corresponding value.

Data is stored as key : value pairs

 Keys are also called properties

 Values can be:

o Primitive values (number, string, boolean)

o Other objects

o Functions (called methods)


 Objects are mutable (can be changed after creation)

Syntax:

let objectName = {
key1: value1,
key2: value2
};

Example:

let student = {
name: "Akhila",
age: 20,
course: "[Link]"
};

[Link]([Link]);

Adding Properties:

[Link] = "Hyderabad";

Accessing Properties:

[Link]([Link]); // dot notation


[Link](student["age"]); // bracket notation

Object with Method:

let person = {
name: "Ram",
greet: function() {
[Link]("Hello");
}
};

[Link]();

Types of Object Creation

Object Literal

let obj = { name: "Akhila" };

Using new Object()

let obj = new Object();


[Link] = "Akhila";
Constructor Function

function Student(name, age) {


[Link] = name;
[Link] = age;
}

let s1 = new Student("Akhila", 20);

ARRAYS IN JAVASCRIPT

Definition:

An array in JavaScript is a special type of object used to store multiple values in a single
variable. The elements are stored in an ordered manner and are accessed using an index
starting from 0.

Syntax:

let arr = [value1, value2, value3];

Example:

let numbers = [10, 20, 30];


[Link](numbers[0]); // 10

Array Methods

1. push()

Definition: Adds one or more elements to the end of the array.

[Link](4);

2. pop()

Definition: Removes the last element from the array.

[Link]();

3. shift()

Definition: Removes the first element from the array.

[Link]();

4. unshift()

Definition: Adds elements to the beginning of the array.

[Link](1);

5. length
Definition: Returns the number of elements in the array.

[Link]([Link]);

6. includes()

Definition: Checks whether an element is present in the array.

[Link](2);

7. indexOf()

Definition: Returns the index of an element, or -1 if not found.

[Link](2);

8. slice()

Definition: Returns a new array by extracting a portion of the original array.

[Link](1, 3);

DATE OBJECT IN JAVASCRIPT

Definition:

The Date object is used to create, store, and manipulate date and time values in JavaScript.

Syntax:

let d = new Date();

Example:

let today = new Date();


[Link](today);

Date Methods

1. getDate()

Definition: Returns the day of the month (1–31).

[Link]();

2. getMonth()

Definition: Returns the month (0–11).

[Link]();

3. getFullYear()

Definition: Returns the year.


[Link]();

4. getHours()

Definition: Returns the hours (0–23).

[Link]();

5. getMinutes()

Definition: Returns the minutes (0–59).

[Link]();

6. getSeconds()

Definition: Returns the seconds (0–59).

[Link]();

7. setFullYear()

Definition: Sets or changes the year.

[Link](2030);

MATH OBJECT IN JAVASCRIPT

Definition:

The Math object is a built-in object that provides mathematical constants and functions to
perform calculations.

Example:

[Link]([Link](16));

Math Methods

1. [Link](x)

Definition: Returns the square root of a number.

[Link](16); // 4

2. [Link](x, y)

Definition: Returns x raised to the power y.

[Link](2, 3); // 8

3. [Link]()
Definition: Returns a random number between 0 and 1.

[Link]();

4. [Link](x)

Definition: Rounds a number down to the nearest integer.

[Link](4.7); // 4

5. [Link](x)

Definition: Rounds a number up to the nearest integer.

[Link](4.2); // 5

6. [Link](x)

Definition: Rounds a number to the nearest integer.

[Link](4.5); // 5

7. [Link]

Definition: Returns the value of π (pi).

[Link];

You might also like