JavaScript
JavaScript
04-09-2023
Introduction
Introduced by Brendan Eich in 1995.
It became an ECMA standard in 1997
ECMA – European computer manufacture association 1997
JavaScript and java are completely different language, both concept and design
JavaScript is the world’s most popular programming language which is used on
browser to make webpages dynamic
Netspace : It is a browser
Java JavaScript
Programming Language Scripting language (It works on frontend)
(It works on middleware)
Strictly typed Weakly types
Eg: Eg;
Environment of JavaScript
NODE JS
Node is combination of a bundle of chrome V8 engine and built in methods in C++.
It serves as an environment to run JavaScript outside the browser.
This invention helped JS to gain its popularity in usage as a backend language.
Characteristic of JavaScript
Purely object orientated and object based. (Both primitive and non-primitive data types
are considered as object)
Interpreted language.
Case Sensitive.
Synchronous (It follows SINGLE thread architecture which has only one call stack)
<script>
console.log("this is internal")
</script>
</body>
</html>
EXTERNAL
In html
<script src="../js/scriptSample.js"></script>
</body>
</html>
In CSS
console.log("this is external")
06-09-2023
Token
Reserving something for someone.
Smallest unit for every programming language.
There are 3 types
1. Keyword
2. Identifiers
3. Data Literals
Keywords
Data Literals
Data’s which you are using in JS program
1. String
2. Number
3. BigInt
4. Boolean
5. Null: we use null in absence of data.
6. Undefined: Given by the JS engine
7. Object
Primitive Non-primitive
String Object
Number
Boolean
Null
Undefined
typeof :
It is keyword
It is a special operator
It is a unary operator
It will tell what kind of data type
Data type
String:
Set of Character consider Sting in JS
We declare string in 3 ways
Ex:
var ename=`smith's has iphone which has "apple13ver",he brought is for
Rs.${mobilerate}`
console.log(ename);
2.
Ex:
Number:
Number are consider as number in java.
We don’t have any data type.
To access method or member use ‘.’ Dot
Ex:
console.log(Number.MAX_SAFE_INTEGER)
console.log(Number.MIN_SAFE_INTEGER)
Power: **
Multiplication: *
Range:
Max range:
console.log(Number.MAX_SAFE_INTEGER)
console.log(2**53-1).
Min range:
console.log(Number.MIN_SAFE_INTEGER)
console.log(-(2**53-1))
07-09-2023
Null
It is a keyword.
It has a value in JS
In the absence of data, we will be using null.
Undefined
var a;
It will create a memory block.
It is a keyword.
It has a value in JS
When a variable is declared in JS engine implicitly assign a value called undefined.
Boolean
From the user either you want to get yes or no.
In JS will be having Boolean data type (true/false).
Object
Any real entity which is existing in the real world.
JS object will be in the form of key & value (collection of named values).
Object in JS considered as non-primitive datatype.
Understanding the execution of Java script
SRC
Browser JS Engine Global Execution
Context
var a; //Declaration
console.log(a)
Variable Functional
Phase /Execution Phase
1. It will allocate memory
2. Top to bottom
Output
Console (or)
Document
Every time when JS engine runs a JS code, it will 1st create a ‘global execution context’.
A named block of memory which is used to store a value is known as variables (Container
to store data).
Note:
1. In JS variables are not strictly typed, it is dynamically typed. Therefore, it not
necessary to specify type of date during variable declaration.
2. In a variable we can store any type of value.
3. It is mandatory to declare a variable name before using.
Ex:
var a; //Declaration
a= 10; // Initialization or assigning
console.log(a); //10
let b ;
b=10;
console.log(b) //10
const c=30; //Declaration and initialization
console.log(c); //30
Note:
When a variable is declared in JS, JS engine implicitly assigns undefined value to it.
Ex:
var a ;
console.log(a) //undefined
Var (Playboy)
var a; //Declaration
a=10; //initialization
a=20; //Re-initialization
var a=30; //Re-Declaration and Re-initialization
var b=30; //Declaration and initialization
Const (serious guy)
const love = “marriage” // Declaration and initialization
cont love; //Declaration is not possible
love = “priya” // initialization is not possible
love = “akshaya” // Re - initialization is not possible
const love = “living together” //Re- Declaration and Re-initialization is not possible
08/09/2023
Inside window /browser we have predefined member, predefined member also consider as
an object.
Ex: console.log(window.console)
Example 1:
Variables Execution
console.log(“start”) a: undefined , 10 , 20 console.log(“start”)
var a; a=10
a=10 b: undefined , 20 console.log(a)
console.log(a) a=20;
a=20; console.log(a)
console.log(a) b=20;
var b=20; console.log(b)
console.log(b) console.log(“end)”
console.log(“end)”
Output:
start
10
20
20
End
Example 2:
console.log(“start”)
Variables Execution
var a=40;
console.log(a) a: undefined , 40, 50, console.log(“start”)
var a=50; 70 a=40
console.log(a) console.log(a)
var b=60; b: undefined , 60, 80 a=50;
console.log(b) console.log(a)
var b=80; b=60;
console.log(b) console.log(b)
a=70; b=80;
console.log(a) console.log(b)
console.log(“end”) a=70;
console.log(a)
Output: console.log(“end)”
start
40
50
60
80
70
end
Example 3:
Variables Execution
console.log(“start”)
a: undefined , 70, console.log(“start”)
var a;
smith console.log(a)
console.log(a)
a=70;
a=70;
b: undefined , true, 80 a=smith
a=smith;
console.log(a)
console.log(a)
b=true;
var b=true;
console.log(b)
console.log(b)
b=80;
b=80;
console.log(b)
console.log(b)
console.log(a)
console.log(a)
console.log(b)
console.log(b)
console.log(c)
console.log(c)
console.log(a)
console.log(“end”)
Output:
start
undefined
smith
true
80
smith
80
uncaught error ,c is not defined
11/09/2023
Type Coercion
Converting one data type to another data type
There are two types of type coercion
1. Implicit
2. Explicit
var a = "5";//String
var b = 1;//number
var c = a+b;
console.log(c) //51
console.log(typeof c)//number converted into string.
console.log("ta"+"mil") //tamil
console.log("ta"+5) //ta5
console.log(12+12) //24
var a = "5"
var b = 4
var c = a-b;
console.log(c)
console.log(typeof c) //1
console.log(isNaN("1a")) //true
console.log(isNaN("25")) //false
POP-UP
If we want to alert the user, we use pop-up.
There are 3types
1. Simple alert
2. Confirm alert
3. Prompt alert
Simple alert
Alert the user with information, there is no return type.
Ex:
var a1 = alert("Item has been added")
console.log(a1)
Confirm alert
Alert the user with information, there is Boolean (true/false) as return type.
Ex:
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JS_task</title>
</head>
<body>
<script src="../js/confirm_alert.js"></script>
</body>
</html>
JS:
while(temp){
var a2 = confirm("please turn on your location");
if (a2){
window.location = "https://www.wikipedia.com";
temp = false;
}
else{
temp = true;
}
}
Prompt Alert
Alert the user with information, this return the input value given by the user.
Ex:
var a1 = prompt("enter your name: ")
console.log(a1) //Akshaya
console.log(typeof a1) //string
console.log(str) //true
console.log(typeof str) //string
Case 2:
For number:
var num1 = Number("1a")
console.log(num1) //NaN
Case 3:
For Boolean:
1. var bool = Boolean(1)
console.log(bool) //true
console.log(typeof bool) //boolean
False :
1. undefined
2. null
3. 0
4. “” (empty string)
12/09/2023
Scope
Visibility of member
Block:
{
//Set of statements
}
Types of Block:
1. Named block
Controller have some restriction
while (n>10) {
}
2. Unnamed Block
Controller never have some restriction to go inside the block
TYPES OF SCOPE
Ex for scope:
var
var a = 10;
{
console.log(a)
}
console.log(a)
var a = 10;
{
let b = 20;
const c = 40;
console.log(b)
console.log(c)
console.log(a)
}
console.log(b) //Uncaught ReferenceError: y is not defined
console.log(c) //Uncaught ReferenceError: y is not defined
console.log(a)
Variables Execution
a: undefined , a=10; Output:
10 { 10
b=20 20
b: undefined , C=40 40
20 console.log(b) 10
console.log(c) Uncaught ReferenceError: b is not defined
c: undefined , console.log(a)
40 }
console.log(b)
console.log(window.x)
console.log(window.y)
var x = 10;
{
let x = 40;
console.log(x)
}
console.log(x)
b: undefined ,
40
---------------------------------------------------------------
let a =20;
{
var a = 10; Identifier 'a' has already been declared
}
Variable hoisting
1. Ex:
console.log(x)
var x;
x = 10;
console.log(x)
{
console.log(x) //cannot access 'x' before initialization
let x = 40
console.log(x)
}
console.log(x)
2. Ex:
var a =10;
{
let b=40;
{
console.log(a)
console.log(b)
}
console.log(b)
}
console.log(a)
console.log(b)
console.log(a)
Variables Execution
window: a=10; Output:
{ 10
a: undefined , 10 b=40; 40
{ { 40
b: undefined , 40 c.l(a) 10
{ c.l(b) Uncaught ReferenceError: b is
} not defined
} c.l(b)
}
} c.l(a)
c.l(b)
3. Ex:
var a = 10;
{
let b = 40;
{
let b =60;
{
console.log(b)
}
} Output:
b = 20; 60
console.log(b) 20
}
VAR LET CONST
Hoisting
TDZ (temporal dead zone)
13-09-2023
Type Coercion
The process of converting one type of data into another data type.
Type conversion (implicit type casting)
IMPLICIT TYPE:
The process of converting one data type into another data type by JS engine implicitly
(implicitly type casting), when wrong type of data is used in the expression is known as
type coercion (or implicit type casting)
Ex:
console.log(10+’20’); //1020, number is converted into string
console.log(10-‘2’); //8, string is converted to number
console.log(5-‘a’); //NaN, the string does not have a valid numeric value
Hence it is converted to a special number ‘NaN’.
What is NaN ?
NaN(Not a number) is number
Any arithmetic operation with NaN, result is NaN.
Console,log(5-“1a”); //NaN
EXPLICIT TYPE:
The process of converting one type of value to another type of value by developers is
known as explicit typecasting.
Ex:
console.log(typeof ‘a’); //string
console.log(number(‘a’)); //NaN
console.log(‘123’+10); //12310
console.log(Number(‘123’)+10); //133, string ‘123’ is converted to number
console.log(Number(‘123a’+10)); //NaN
POPUP’S
Simple alert - user can able to click ok (we can alert the user)
Confirm alert - - user can able to click ok and cancel (return type)
Prompt alert – user can able to give data’s
(Data’s getting from the prompt default it will be in string type)
Ex:
let a;
console.log(a); //Undefined
a = 10;
Ex:
console.log(a); //reference error(TDZ)
let a;
a = 10;
STRING:
Keyword Function/
Special Arguments
operator called as
values
Ex:
var str = "Smith"
console.log(str)
console.log(str[0])
console.log(str[0])
Stack Area
@str1001
str1 @002
Address Values
@str1001 Key Value
0 s
1 m
2 i
3 t
4 h
Key Value
@arr003 0 A
1 2
2 3
14-09-2023
OPERATOR
Operators are pre-defined symbols whose work on operands
1. Arithmetic Operators
2. Assignment Operators
3. Comparison (Relational) Operators
4. Logical Operators
5. Bitwise Operators
6. Conditional Operators
7. String Operators
8. Special Operators
Arithmetic operators
var a = 10;
var b = 2;
console.log(a+b)
console.log(a-b)
console.log(a*b)
console.log(a/b) //Using division = Quotient
console.log(a%b) //Using modulus = Reminder
var a = 10;
a+= 10;
console.log(a)
a = a+10
console.log(a)
a-=10
console.log(a)
a*=10
console.log(a)
a/=10
console.log(a)
a%=4
console.log(a)
Comparison operator or relation operator >, <, <=, >=, ==, ===, !=, !==
Equals ==
(Only values)
1. Primitive - non-Primitive
var num = 10;
var num1 = new Number(10)
console.log(num == num1)
------------------------------------------------------
2. Primitive - Primitive
// var str = "smith"
// var str1 = "smith"
// console.log(str == str1)
------------------------------------------------------
3. Non-Primitive - non-Primitive
var str =new String( "smith")
var str1 =new String( "smith")
// console.log(str == str1) // instead of using normal way use .member
console.log(str.valueOf() == str1)
Case 1:
var bool = true
var num = 1
console.log(bool == num) //true
Case 2:
var bool = true
var num = 5
console.log(bool == num) //false
1. Primitive - Primitive
var str = "smith"
var str1 = "smith"
console.log(str === str1) //true
----------------------------------------------------
2. Primitive - Non-Primitive
var str = "smith"
var str1 =new String("smith")
console.log(str === str1) //false
1. Primitive - Primitive
var str = "smith"
var str1 = "smith"
console.log(str !== str1) //false
-------------------------------------------------------
3. Non-Primitive - Non-Primitive
var str = new String("smith")
var str1 =new String("smith")
console.log(str !== str1) //true
||
console.log(true || false) //true
&&
console.log(!true && !true) //false
Conditional operator
Ex:
alert(age)
Instance of:
var str = "smith"
var str1 = new String("smith")
15/09/2023
Function
‘this’ keyword
1. A call stack is a way for the JavaScript engine to keep track of its place in code
that calls multiple functions
2. Stack of function to be executed
3. Manages execution contexts
4. Stack are LIFO last in first out
Example 1:
Variables Execution
console.log("start") this Console.log(a1+a2) //30
function sum(a1,a2){
console.log(a1+a2)
Variables Execution
}
window: console.log("start")
sum(10,20)
sum(10,20)
console.log("end") this
console.log("end")
{
sum
}
Output
start
30
end
start
30
a is not defined
The JavaScript string is a sequence of character
STRINGS:
In JS String can be represented using single, double quotes or backticks.
Note:
The start and end of a string must be done with the help of same quote.
If a text contains single quote then it can be represented using double quotes.
Ex:
Text: I’m a doctor
IN JS: “I’ m a
Backticks:
A backticks can be multiline string.
Ex:
Var hobbies = `My hobbies are:
1. Cricket
2. Movies
3. Stock`;
console.log(hobbies);
Note:
The string represented using backticks is also known temple
The advantage of it is we can substitute and express it using $()
Example:
var str = “smith”
var str = new string (“smith”)
var str = new string (“smith”)
console.log(student.lenght);
console.log(student.toUpperCase());
console.log(student.lowerCase())
console.log(student.repeat(5))
19-09-2023
FUNCTION:
Ex:
console.log(‘start’);
test() //console.log(test)
function test()
{
console.log(“hello”)
}
console.log(‘end’)
When we try to log the function name the entire function definition is printed
PARAMETERS:
Ex:
function sum(a,b)
{
console.log(a+b);
}
Here a and b are variables local to the function sum.
ARGUMENTS:
Ex 1:
sum(10,20)---------------------10, 20 are literals used as arguments
Ex 2:
sum(-10+3, -20); -----------//-27
Ex 3:
sum(a,b):------------------- a & b are variables used as arguments
this:
FUNCTION EXPRESSION:
Syntax:
Ex:
const area = function (width, height) {
return width * height;
};
Disadvantages:
The function is not hoisted, we cannot use the function before declaration.
Reason: function is not hoisted, instead variable is hoisted and assigned with default value
undefined. Therefore typeof a is not function, it is undefined.
outer f x001
Output:
Start
outermost xcall01
10
20
End
TYPES OF FUNCTION:
1. Named Function:
function add(a, b) {
return a + b;
}
console.log(add(5,4));//9
2. Anonymous Function:
console.log(subtract(10,6));//4
3. Arrow Function:
The primary purpose of using an IIFE is to create a new scope for variables, preventing
them from polluting the global scope.
Syntax :(function() {
// code here
})();
Ex:
let no1 = 5;
let no2 = 6;
5. Callback Function:
6. Recursive Function:
A recursive function in JavaScript is a function that calls itself during its execution.
function factorial(n) {
if (n <= 1) {
return 1;
}
return n * factorial(n - 1);
}
console.log(factorial(5));//120
7. Higher-Order Function:
function x(){
console.log("higher order as function");
}
function y(x){ //y is a higher order function
x();
}
y(x);
2. By returning them
function printfunc(){
return function(){
console.log(" From return type function.")
}
}
var x = printfunc();
x();
8.Generator Function:
A generator function in JavaScript is a special type of function that allows you to control
the execution flow and pause/resume it at certain points.
Generator functions are defined using the “function*” syntax and use the “yield” keyword
to produce a sequence of values lazily, one at a time.
function* generateSequence() {
yield 1;
yield 2;
yield 3;
}
Note: The yield operator is used to pause and resume a generator function.
let generator = generateSequence();
console.log(generator.next().value); // Output: 1
console.log(generator.next().value); // Output: 2
DOM TREE
DOM
Note:
Any modification done using DOM is not updated to the original html document.
Therefore, once we reload a page all the modification done using DOM will be lost.
We can write the content on the browser dynamically with the help of write and
written method of document object.
Ex:
To display a message on the browser page from java script code:
document.write(“hi”)
Dom is an API provided by the browser.
Dom is not a java script, it is built using java script.
Dom is an object oriented representation of html file.
Every time an html document is given to the browser, it automatically generated it
can be accessed and modified using the root node document in JavaScript.
Uses of Dom:
1. Change and remove element in the Dom on the webpages.
2. Change and add CSS Style to the element.
3. Read and change content of the webpage.
4. Create new elements
5. Attach event listener.
METHOS:
Create Element
For this method we need to pass the tag name of an element as string, it returns the
element.
Append:
For this method we have to append the element to the body once it is created by
DOM CreateElement.
Append Child:
For this method we have to append children the element to the body once it is
created by DOM CreateElement.
TO OBTAIN THE ELEMENTS FROM DOM:
Methods of Dom:
1. getElementById():
Ex:
let e1 = document.getElementByName(“heading”)
console.log(e1[0]);
console.log(e1[0].textContent);
e1[0].textContent = ‘welcome’;
console.log(e1[0].textContent);
DOM PROPERTIES:
1. firstElementchild
2. firstchild
3. lastElementchild
4. lastchild
5. children[0]
6. parentElement[]
7. nextSibling
8. nextElementSibling
Note: To access node use “ [values] ”.
EVENT:
Event
EventHandler/EventListener
Event Event
As an attribute As a DOM method
1. onclick Syntax:
2. onfocus addEventListener(“event”,call
back function, boolean)
Event Flows
Event Capturing: Event handler that gets triggered whenever we click on an element, like
onclick.
Event bubbling: In event bubbling the event starts at the target element (most specific
element) and then flows in the upward direction of the DOM tree.
13/10/2023
ASYNCHRONOUS:
Statement 1
Takes
time
Statement 2 Database
Statement 3
Statement 4
Callback
async - always return a promise
console.log(res);
console.log("Bye");
}
asyncstatus();
ARRAY:
Array is a huge block of memory which is used to store multiples values of different types.
To create an array
a. In JS array is an object.
b. We can create array object in different ways
1 2 3 4 5
6
Const obj: Java Web J2EE SQL Python
0 1 2 3 4
Index value
/Reference
value
Associative array:
In JS array is not in type of out associate array.
Use always Const.
console.log(arr1[0]);
console.log(arr1[1]);
console.log(arr1);
console.log(arr1);
--------------------------------------------------------------
Using array literal []:
Syntax:
Let arr = [value 1, value2, value3…] here ‘arr’ is the literal which stores the address of
array object.
Ex:
let arr = [10,20,30];
console.log(arr)
Syntax:
let arr2 = new array(): here ‘()’ is function call
Eg:
We can access array elements with the help of array object reference, array operator &
index.
Syntax:
array_obj_ref[index]
Index: it is a number starts with zero and ends with the (length of array object - 1)
Ex:
let hobbies = [‘reading’,‘writing’,‘playing’,‘cricket’]
console.log(hobbies[1]);//writing
--------------------------------------------------------------
Iterate element inside an array
}
--------------------------------------------------------------
To append to order list
console.log(subject[i])
}
--------------------------------------------------------------
Array as homogeneous and hetrogeneous
var data_type = [
"smith",
99,
9n,
true,
false,
undefined,
null,
{
ename: "smith"
}
["smith"],
function(){
console.log("array js")
}
];
--------------------------------------------------------------
console.log(student_detail[0]);
--------------------------------------------------------------
Task:
if(Option == 1){
}
else if(Option == 2){
var subtraction = num1-num2;
alert(`The difference of ${num1} and ${num2} is ${subtraction}`);
else{
alert("Kindly enter correct option")
}
--------------------------------------------------------------
function sum(a,...b){
console.log(a)
console.log(b)
}
sum(10,20,30,40)
console.log(boy1);
console.log(boy2);
console.log(girl1);
console.log(boy2);
--------------------------------------------------------------
for - of/for - in
for(var x of arr){
console.log(x)
}
--------------------------------------------------------------
var ol = document.createElement("ol");
document.body.append(ol);
for(var x of arr){
if(x.length %2 ==0){
var li = document.createElement("li");
ol.appendChild(li);
li.textContent = x;
}
}
--------------------------------------------------------------
var arr = ["chennai","Banglore","Pune","Kolkata","Coimbatore"]
for ( var x in arr){
console.log(x)
}
-------------------------------------------------------------
li.textContent = arr[x] ;
}
}
--------------------------------------------------------------
console.log(arr)
arr[0] = "simth";
arr[1] = "rose";
console.log(arr)
console.log(arr);
--------------------------------------------------------------
var hobbies = [
"football",
"singing",
"reading",
"cooking",
"travelling",
"sleeping",
"house cleaning",
"driving",
"cycling",
"trekking",
"reading"
];
1. lenght method
console.log(hobbies.length)//11
console.log(hobbies.sort());
hobbies.push("Swiming", "cricketing")
console.log(hobbies)
console.log(hobbies.push("dancing"))
hobbies.pop();
console.log(hobbies);
hobbies.unshift("firstElement","secondElement")
console.log(hobbies)
6. shift method: remove the 1st element from the tail of an array
hobbies.shift();
console.log(hobbies);
console.log(hobbies)
console.log(hobbies)
Map, reduce, and filter are all array methods in JavaScript. Each one will iterate over an
array and perform a transformation or computation. Each will return a new array based on
the result of the function
Map
The map() method is used for creating a new array from an existing one, applying a
function to each one of the elements of the first array.
Syntax
console.log(doubled);
Filter
The filter() method takes each element in an array and it applies a conditional statement
against it.
The element gets pushed to the output array. If the condition returns false, the element
does not get pushed to the output array.
If the condition returns false, the element does not get pushed to the output array.
Examples
In the following example, odd numbers are "filtered" out, leaving only even numbers.
The reduce() method reduces an array of values down to just one value. To get the output
value, it runs a reducer function on each element of the array.
The callback argument is a function that will be called once for every item in the array.
This function takes four arguments, but often only the first two are used.
Examples
console.log(sum);
Object
1. literal
{name : value}
Example:
Var student = {
name: “chris”,
age: 21,
studies: “computer science”
};
2. new keyword
Example:
3. Object constructor
Function stud(name,age,studies){
this.name = name;
this.age = 21;
this.studies = studies;
}
OBJECT:
1. Any substance which has its existance in the real world is known as OBJECT.
2. Every object will have states(attributes of feeds which describe them).
3. Every object will have actions (behaviours)
4. JavaScript object are just a collections of named values, these named values are
usually referred to as properties of object.
EX:
1-car:
states of car: model,color,price
actions of car:accelarate, brake, start, stop
2.webpage:
states of webpage:url,data/content on webpage.
actions of webpage.scroll,hover,click
Note:
In programming an object is a block of memory which represents a real world.
The properties of real world object are represented using variables -The actions of
real world object are represented using METHODS (FUNCTIONS).
1. In javascript object is a collection of attributes and actions in the form of
key&value pairs enclosed
2. within curly braces()
3. Key represents properties/attributes of an object
4. Value represents state of an object.
1. Object literals
const obj = {
name: "sheela",
age: 24,
profession: "software engineer", };
console.log(obj);
console.log(obj.name)
console.log(obj.salary = 200)
delete obj.profession
2. Using function
const obj = {
name: "sheela",
age: 24, profession: "software engineer", };
console.log(obj))
//to add key: value pair into an object
obj_salary = 2000; //add salary to object console.log(obj);
obj.name = 'smith'; // to change value of name is replaced with 'smith'
console.log(obj)
//to delete a key from an object
delete obj salary;
console.log(obj) //salary will be deleted
Object.assign();
Syntax
Object.assign(target, sources);
const abj1 = {
name: "sheela",
age: 24, profession: "software engineer", };
let source = (
living: "bangalore",
company: "test yantra", };
console.log(Object.assign(objl, source));
console.log(obj1)
Values()
const obj = {
name: "sheela",
age: 24,
profession: "software engineer",
console.log(Object. values(obj)) console.log(obj)
Keys
const obj = {
name: "sheela",
age. 24,
profession: "software engineer", };
console.log(Object.keys(obj)) console.log(obj)
seal
seal- it won't allow to add any more object keys and values
const obj = {
name: "sheela",
age: 24,
profession: "software engineer",
console.log(Object.seal (obj));
obj.salary= 200;
console.log(obj) obj.name = "smith"
console.log(obj)
Seal
const obj = {
name: "sheela",
age: 24,
profession: "software engineer",
console.log(Object.seal (obj));
obj.salary= 200;
console.log(obj) obj.name = "smith"
console.log(obj)
const obj = {
name: "sheela", age: 24,
profession: "software engineer", };
var s1 = Object.entries(obj);
console.log(s1)
console.log(s1.flat())
var arr = [1, 2, 3, 4, 5,[[[[6]]]]]
console.log(arr. flat (4))
Freeze-it won't allow to modify any more object keys and values
const obj = {
name: "sheela",
age: 24,
profession: "software engineer",
console.log(Object.freeze(obj));
obj.profession = "tester";
obj.salary = 200; console.log(obj);
Note:
1. If the key is not present in the object then we get 'undefined' as the value.
2. The objects in JavaScript are mutable (state of the object can be modified) in
nature.