0% found this document useful (0 votes)
18 views

Javascriptnotes

The document discusses various JavaScript concepts like internal and external JS, DOM, BOM, functions, objects, properties, methods, events and loops. Key concepts covered include using getElementById and querySelector to select elements, setting styles and properties, and using setTimeout, setInterval, confirm, prompt functions.

Uploaded by

palakbharti112
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Javascriptnotes

The document discusses various JavaScript concepts like internal and external JS, DOM, BOM, functions, objects, properties, methods, events and loops. Key concepts covered include using getElementById and querySelector to select elements, setting styles and properties, and using setTimeout, setInterval, confirm, prompt functions.

Uploaded by

palakbharti112
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 21

Internal JS

==================
<script>
JS Code
</script>
--------------------------------
External JS
==================
filename.js
p1.js
Lines of JS code
----------------------------------------
--------------------------------------
Demo1..html
<script src="p1.js"></script>
===================
DOM vs BOM

BOM stands for browser object model providing some methods related to browser .

alert()
prompt()
confirm()
setTimeout()
setInterval()
clearInterval()
history()
print()
pause()
play()

Browser related functions are defined in window object.

window is the primary object of java script.


-----------------------------------------------------------------------------------
---------------------------
object1
============
fun1()
fun2()

object.membername
object1.fun1()
object1.fun2()
------------------------

alert()
============
=>alert () is used to print output runtime box.
=>It is defined in window object.

Syntax
-----------
window.alert("massage")
=========================
promt()cx
==========
promt function is used to take input by user on runtime.
=>return type of prompt function is string.
cancel=>when user click on cancel it return null value
ok=>when user click on ok it return entered value
====================================
syntax
=======
window.prompt("fieldname","placeholder")
ex:
var name=window.prompt("name","Enter your name..")//"RAM"
===================================================================================
=============
DOM =>DOM stands for document object model providing some property and methods
related to document object.
Document related functions are defined in document object.

write()
getElementById()
getElementsByTagName()
getElementByClassName()
getElementByName()
querySelector()
querySelectorAll()
etc...

document.write()
document.getElementById()

<input type="text" id="txt1"/>


<button>GET VALUE</button>

getElementById()
==================
=>getElementById () is used to select HTML element on the basis of HTML Id..
=>return type of getElementById() function is current object.
=>This is defined in document object.
Syntax
========
document.getElementById("IDOHTMLTAG");
Ex
===
<input type="text" id="txt1"/>
document.getElementById("txt1")

How to set style to HTML element by using JS.


================================
Syntax
======
object.style.propertyName="value"
Exa:
<img src="images/movie2.png"/>
var x="document.getElementById("im1")
x.style.background="red";
x.style.border="10px solid red"
x.style.height="200px"
x.style.width="200px"
x.style.borderRadius="200px"
x.style.marginTop="10px"
=====================================
finction functionName{
block of re-usable code
-------------------------------
}
functionName(){
code
}
function demo()
{
code
}demo()
<body onload="demo()">
<img src="images/movie2.png"/>
<button>Click Me</button>
border
height
transform
transition
border-radius
=============================
value
=====
value property is used to set/get value to the selected HTML form-control(web-
form input,select,textarea,datalist)

get
------
x=object.value;

ex:
<input type="text" id="txt1"/>Palak
<button onclick="demo()">CLICK ME</button>
function demo()
{
var a=document.getElementById("txt1")
alert(a.value)
}
set
-------------
object.value="datavalue"
ex:
====
<input type="text" id="txt1"/>
<input type="button" onclick="myfun()" value="set value"/>
<script>
function myfun()
{
var obj=document.getElementById("txt1")
obj.value="Techpile"
obj.style.border="3px solid red";
}
</script>
===============
write()
=========
write function is use to display output on new document.
write function is defined in document object.'
=>tags are applicable here
syntax
======
document.write(data)
ex
===
document.write("<h1>techpile technology</h1>");
=========================================
innerText
---------------------
ex
============
query selector function is used to select first matches element on the basis of CSS
selector (Id,class,tag,attribute etc)
query selector function is defined in document object.

syntax
-------------
document.querySelector ("CSS_SELECTOR")

Exa:
----------
<p>P1</p>
<p class="t1">P2</p>
<p class="t1">P3</p>
<p id="p1">P4</p>
document.querySelector("p")//first paragraph is selected
document.querySelector(".t1")//<p class="t1">P2</p1>
document.querySelector("#p1")//<p class="p1">P4</p1>
=================================================
length property is used to find length or any collection (array,string list) etc.
Syntax
----------
var a="RAM"
document.write(a.length)//3
var arr =["HTML","CSS","JS","JQUERY"]
document.write(arr.length)//4
======================================================
src property is used to set/get value of src attribute .

get
-------------
syntax
-------------
object.src
EX:
<img src="1.jpg"/>
var x=document.querySelector("img").src
document.write(x)//images/1.jpg

Set
------------
object.src=datavalue
<img src="images/1.jpg"/>
//document.querySelector("img").src="images/2.jpg"
var x=document.querySelector("img")
x.src="images/2.jpg"
---------------------------------------------------------------------------------
setInterval()
----------------------
setInterval function is use to execute a group of statement for every even time
interval .
This function is defined in window object .

Syntax
--------------
window.setInterval("functionname()",timeInMillisecond)
window.setInterval(functionname,timeInMillisecond)
Ex:
------------
function demo(){
group of statement}
window.setInterval("demo()",1000)
window.setInterval(demo,1000)
===========================================================
type
======
type property is used to set/get value of type attribute.

get
=====
object.type
ex:
---------
<input type="radio"/>
var x=document.querySelector("input ").type
alert(x)//radio

set
-----------
object.type=datavalue
ex:
<input type="password"/>
//document.querySelector("input").type="text"
var x=document.querySelector("input")
x.type="text"
===============================================================
=>Set timeout is used to execute once a group of statement after given time
interval.
=>set timeout function is defined in window object .

syntax
----------
window.setTimeout("funtionname()",time in millisecond)
window.setTimeout(funtionname,time in millisecond)
ex:
function myfun(){
}
setTimeout(myfun,3000)
setTimeout(myfun,3000)
=================================================================
function demo(){

}
Anonymous function
ex
-------
function(){
}
=>window.setTimeout(function(){
alert("ok")
},3000)
==================================================================
confirm
-----------------
=>Confirm box is used to take conformation with user on run time .
=>It has two buttons cancel and ok.
=>OK=When user clickon ok button it return true
=>cancel =when user click on button it return
this function is defined in window object .
window.confirm("message")
ex
--------
window.confirm("are you sure want to delete record?")
=================================================================
location
-----------
window.location="url"
window.location="https://.techpilelko.in"
-----------------------------------------------------------------------------------
----------------------------------------------------
open()
------------
open function is used to open URL on new window.
sytax
-----------
window.open("URL","_blank","top=50px,left=50px,height=400px,width=350px")
ex
-------
window.open("ww.techpile.in","_blank","height=500px",width=400px")
===========================================================================
window.setInterval(demo,500)
==============================
Array in JS
-----------

=> In js Array is a collection of hetrogeneous data type element.


=>Idexing of array is starts from zero and last index is (n-1) where n is length
array.
Declaration of Array
var arrayName=[items,items2,item3,...........itemsN ]
var arrayName=new Array(item1,item2,item3,..........itemN)
Ex
----
var arr=[10,10.5,"Ram",true,false,104]
var arr=new Array[10,10.5,"Ram",true,false,104]
How to access elements of array
=======================
arraynName[index]
Ex:
------
arr[0]//10
arr[1]//10.5
arr[arr.length-1]//104
===========================================================
string intepolation
-------------------------
`item of first index is: ${(variable)}<br/> item of second index is:${(variable)}`
`item of first index is: ${arr[0]}<br/> item of second index is:${a[1]}`
===========================================================
How to assign item in array
Syntax
----------
arraName[index]=items
Ex
-----
var arr=[]
arr[0]="Ram"
arr[1]=100
a[2]=true
======================================================
for(var i=1;i<=3;i++)
{
}

-----------------------------------------------------------------------------------
----------------------
for ..in=>returns index in variable.
=>If we want to execute a group of statement for every elements present
in given collectionthen we have to use for..in or for..of loop in javascript.
-------------
Syntax
---------
for (var x in collection){
statement
statement
statement
}
ex
------
var arr =["RAM","MOHAN","AJAY"]
for(var x in arr){
alert("Techpile")
statement
}
----------------------------------------------------------------------------------
for ..of=>Returns item in variable.
Syntax:
==========
for(var variableName of collection)
{
statement
statement
statement
}
ex
---
<script>
var arr =["RAM","MOHAN","AJAY"]
for(var x of arr){
alert(x)
}
</script>
ex:
var x="Techpile"
for(var a in x){
alert(a)//0,1,2,3,4,5,6,7
}
-------------------------------------------------------------------------------
var x="RAM"
for (var a of x){
alert(a)//Items //R,A,M
}
-------------------------------------------------------------------------------
var x="RAM"
alert(x[0])//R
alert(x[1])//A
alert(x[2])//M
================================================================
function is a block of reusable code which is used to perform particular task.

Type of function
==============
1.Built in function
2.User defined function

1. Built in function=>
---------------------------
Functon which is predefined in system client is known as Built in function.
Ex-getElementById,getquerySelector,setTimeout,setInterval etc.

-----------------------------------------------------------------------------------
--------
2.User Defined function=>
----------------------------------------
The function which are defined by user based on bussiness
requirements are known as User defined function.
========================================================================
In javascript calling of function is handle by multiple js Events

Events
========
onclick
onchange
ondblclick
onload
onmouseover
onmouseleave
onkeyup
onkeypress
oncut
onfocus
onpaste
oncopy
onblur
etc.
=========================================================================
Syntax
--------------
function functionName()
{
statement
statement
statement
}
ex:
----
function demo(){
alert("ok")
}<p onclick="demo()">Click Me</p>
==========================================================================
Anonymous Function
================
The function which does'nt have any name is called Anonymous name

Syntax
-----------------
function(){
statement
statement
statement}
----------------------------------
Ex:
window.setInterval(function(){},2000)

-----------------------------------------------------------------------------------
--------------------------------------
ES6
====
ECMA is a standard to writing JS code.

Arrow function
------------------------
var demo=()=>{

}
Arrow anonymous function
----------------------------------------
()=>
{
}
window.setInterval(()=>{},2000)
=========================================================
function with parameter
================
Syntax
------------
function
functionName(param1,param2,..............,paramN){
statement
statement
statement
}
parameter
=========
parameter provides input to the function ,at the time of function calling
compulsary we
have to provide value to that parameter otherwise we will get error.

function Myfun(x,y,z)//here x,y,z are formal arguments


{
alert(x)
alert(y)
alert(z)
}
Myfun(10,20,30)//here 10,20,30 are actual arguments
Arrow function with parameter
======================
Syntax
------------
var demo=(a,b)=>
{
statement
statement
statement
}
calling
---------------
demo(20,30)
===========================================================================
function with default parameter
=====================
function demo(a=20,b=30,c=40){
alert(a+b+c)
}
demo()//100
demo(40)//120
demo(30,40)//120
demo(30,40,200)//270
===========================================================================
this
=======
this keyword is used to select current object.
Ex
----------
<h1 onclick="demo(this)">Click Me</h1>
function demo(x){
alert(x)//objectHTMLHeadingElement
}
===========================================================================
function demo(a=1,b=2,c=3)
{
var res=a*b*c
alert(res)}
-------------------------------------------------------------------------
demo()//6
demo(10)//60
demo(10,20)//600
demo(10,20,30)//6000
demo(10,20,30,40,50,60)
------------------------------------------------------------------------
rest operator
------------------------
If we want to call a function with multiple actual argument then we have to use
rest operator.
rest operator created by (...parameter)
=>rest parameter stores values in form of array.
============================================================
function demo(x,...y)
{
statement
statement
statement
}
demo(10)//x=10,y=[]
demo(10,20)//x=10,y=[20]
demo(10,20,30,40,50)//x=10,y=[20,30,40,50]
---------------------------------------------------------------------------------
function demo(a,...b){
}
demo(10,20,30,40,50,60)//a=10 b=[20,30,40,50,60]
-----------------------------------------------------------------------------------
---
Arrow function
------------------------------
var demo=(x,...y)=>
{
statement
statement
statement
}
demo(10)//x=10,y=[]
demo(10,20)//x=10,y=[20]
demo(10,20,30,40,50)//x=10,y=[20,30,40,50]
====================================================
setAttribute()
==========
=>setAttribute function is used to set value of specified attribute.
Syntax
=========
object.setAttribute("AttributeName","value")
<input id="t" type="text"/>
var x=document.querySelector("input")
x.setAttribute=("type","radio")

-----------------------------------------------------
getAttribute()
=>It is used to get value of specified attribute.
Syntax
=========
var x=object.getAttribute("AttributeName")
<img src="im1.jpg"/>
var p=document.querySelector("img").getAttribute("src")p//im1.jpg
removeAttribute()
hasAttribute()
hasAttributes()
====================================================================
clearInterval()
--------------------
=>It is used to stop functionality of set interval.
var a=window.setInterval(demo,1000)
window.clearInterval(a)
======================================================================
print()
=====
print() function is used to print document element.
print function i s defined in window.
syntax
=====
window.print()
---------------------------------
forEach function
=>If we want to execute a group of statement for every element present in array
then we have use forEach function.
=>for Each function takes argument as function.
-----------------------------------------------------------------------------------
-------------------------------------------------------
Syntax
---------
var arr=[10,20,30,40]
function demo(data,index,arr){
alert(data)//items(10,20,30,40)
alert(index)//index(0,1,2)
alert(arr)//array 10,20,30,40
}
arr.forEach(demo)
-------------------------------------------------------------------------------
Anonymous
==========
var arr=[10,20,30]
arr.forEach(function(x,y,z){
alert(x)//10//20//30
alert(y)//0//1//2
alert(z)//10,20,30//10,20,30//10,20,30
})
-----------------------------------------------------------------------------------
-----
Arrow function
arr.forEach((x,y,z)=>{
alert(x)//10//20//30
alert(y)//0//1//2
alert(z)//10,20,30//10,20,30//10,20,30
})
-----------------------------------------------------------------------------------
-----
=>forEach is not applicable for empty array or string.
=>here index(y) an array(z) parameter are optional.
=================================================================================
Math object
=============
Math is a object providing some property and methods related to mathematical
operation .

Syntax for accessing Math object


===========================
object.membername
Math.floor()
Math.round()

------------------------------------------------
floor ()
ceil()
round()
random()
min()
max()
sqrt()
cbrt()
pow()
pi()
etc.
=================================================================================
Math x=12.3444 floor=>10
y=10.0003456 floor=>10
z=30.99999=>30
ceil=>11
ceil=>11
ceil=>31
floor function
==========
It is used to return lowest integer value of floating type value.

Math.floor(10.34567)//10
Math.floor(104.9999)//104
Math.floor(10.5)//10
----------------------------------------------------------------------------
ceil function
=========
ceil() is used to return used to return largest integer value of floating type
value.
Syntax
=====
Math.ceil(200.0099)//201
Math.ceil(200.5)//201
Math.ceil(11.0555)//12
-----------------------------------------------------------------------------------
-------
round()
======
round function is used to return nearest integer value of floating type value .
Syntax
==========
Math.round(200.0099)//200
Math.round(200.5)//201
Math.round(11.0555)//11

-----------------------------------------------------------------------------------
------------
random()
=======
random function is used to return random number between 0(include) and 1(exclude)
0-.999
-----------------------
Syntax
======
Math.random()//0-.99999
====================

Events
=======
oncut
oppaste
oncopy event
oncontextmenu
=================
oncopy event will be execute when user select copy option with keyboard/mouse.
<p>TECHPILE TENOLOGY</p>
function demo(){
alert("ok")
}
Using event listener--
================
document.querySelector("p").addEventListener("copy",demo)
=============================
** preventDefault()
===============
preventDefault function is used to prevent( stop) default action.
--------------------------------------------------------------------------------
Syntax
=======
event.preventDefault()
=====================
document.querySelector("body").addEventListener("copy",function(){
event.preventDefault()
})
=====================================================
oncut event is executed when user select cut option with keyboard/mouse.

<textarea>Techpile technology</textarea>
function demo(){
alert ("ok")
}
document.querySelector("textarea").addEventListener("cut",function(){
event.preventDefault()
alert("cut event is disabled")
})
=========================================================
paste
=====
paste event will be executed when user select paste option with keyboard/mouse.
<textarea></textarea>
document.querySelector("textarea").addEventListener("paste",function(){
this.style.color="red";
this.style.background="green"
event.preventDefault()
alert("paste event is disablee")
})
=========================================================
contextmenu
========
contextmenu event will be executed when user right clicked on selected HTML
element.
<div id="dv"></div>
document.querySelector("#dv").addEventListener("contextmenu",function(){
this.style.background="yellow"
event.preventDefault()
alert("Right click is disabled")
})
===============================================================
string
=========
string is a sequence of character enclosed with single or double or backtick.
"string"
'string'
`string`
function of string
-----------------------
1.slice
2. substring
3.substr
4.indexOf
5.astIndexOf
6.split
7.toUpperCase
8.toLowerCase
9.charAt
10.trim
11.trimStart
12.trimEnd
13.padStart
14.padEnd
15.charCodeAt
16.match
17.includes
18.replace
19.replaceAll
20.startsWith
21.endsWith
22.bold
23.fontColor
======================================================
->slice function is use to return a part of string based on strat and end index.
=>Negative index is acceptable here .
Syntax
======
var x="Techpile technology Pvt Ltd."
x.slice(startIndex,endIndex)
Ex
=====
x.slice(3,6)//hpi excluding end index items
x.slice(1)// 1 to end last index
x.slice(-5,-1)
length=end index-start index
substring function is used to return a part of string of given main string based on
start and end index.
=>negative index is not acceptable here.
Syntax
----------
var x="Techpile"
x.substring(startIndex,endIndex)
ex:
==
x.substring(2,5)//chp
x.substring(14)//undefined
x.substring(3)//hpile
==============================================================================
substr
---------
=>substr function is used to return a part of string given main string based
startindex and length of string .
Syntax
====
length=endIndex-strartIndex
var s ="Techpile Technology"
s.substr(startIndex,length)
s.substr(4,3)//pil
s.substr(1,100)//undefined
=================================================================================
charAt()
=========
=>charAt() is used to return single character at specified index.

Syntax
=-====
a.charAt(index)
var a="techpile"
a.charAt(5)// i //returns single character
a[5]
==========================================================
indexOf
==========
var str="abs.xyz.jpg"
var str1="xyz.jpg"
var ext =str.substring(str.lastIndexOf('.'))//.jpg
var ext1 =str1.substring(str1.lastIndexOf('.'))//.jpg
================================================================
Functions of array
============
push
===
=>Push function is used to add item at last position of an array and return length
of updated array .
syntax
----------
var arr=["Ram","Mohan"]
arr.push("item")
Ex:
------
console.log(arr.push("Ajay"))//3
console.log(arr)//["Ram","Mohan","Ajay"]
==================================================================
Pop
===
pop() function is used to remove last element of an array and return removed
element .

var arr=[1,2,3,4]
document.write(arr.pop())//4
document.write(arr)//[1,2,3]
=======================================================================
unshitft ()
----------
unshift function is to add items at begining position of an array and return
length of updated array.
Syntax
------------
var arr=["HTML","CSS","JS"]
document.write(arr.unshift("React JS"))//4
document.write(arr)//["React JS","HTML","CSS","JS"]
===============================================================
shift
-------
=>shift function is used to remove first element of an array and return removed
element.
Syntax
=====
var arr=["HTML","CSS"]
document.write(arr.shift())//HTML
document.write(arr)//["CSS"]
===============================================================
var arr=["Ram","Mohan","Sohan","Rohit","Mohit"]
arr.forEach(function(){
})
Filter()
----------
Filter function is used to filter item of an array based on some condition and
return new array.
=>Filter function is no applicable on empty array.
Syntax
--------
var newArray=array.filter(function(data,i,arr){
return condition
})
Ex:
var arr=["Ram","Mohan","Sohan","Rohit","Mohit"]
var arr1=arr.filter((data)=>{
return data[0]=="R"})
alert(arr1)//["RAM","Rohit"]
======================================================================
MAP Function
===========
If we want to add some modification to every element of array and return new array
then we have to use map function.
Map function is not applicable on empty array.
Syntax
=====
array.map(function(data,i,arr){
return itemWithModification
)}
Ex
-======
var arr=[2,3,4,5,6,7,]//tailing comma
var arr1=arr.map(function(data){
return data*data*data})
document.write(arr1)
=============================================================
shift
unshift
splice
--------
=>splice function is use to add/remove items of an array.
=>It returns removed elements.
array.splice(startIndex,NoOfItemsToRemove,Item1,Item3......ItemN)
Ex:
var arr=["HTML","CSS","JS","JQUERY"]
arr.splice(2,1,"REACT JS ","VUE JS")
alert(arr)//["HTML","CSS"," REACT JS","VUE JS","JQUERY"]

//var x=arr.splice(-1,2,"JAVA")//
//alert(arr)
arr.splice(-3,2,"C# programming","PHP")
alert(arr)//["HTML","C# programming","PHP","JQUERY"]
=====================================================================
Every
-------
=>Every function is used to check whether every element of an array satisfying
given condition or not .
=>If every element of array satisfying given condition then it returns true
otherwise it returns false .
Syntax
-------------
var x=array.every(function(data,i,arr){
return condition
})
var arr=[10,20,9,13,,11]
Ex:
-----------
var arr=["Java","JavaScript","Jquery"]
var x=arr.every(function(data){
return data[0]=="J"
})
alert(x)//true
var arr1=[10,20,30,40]
var y=arr1.every(function(d){
return d<5
})
alert(y)//false
=============================================================================
Delete
=====
=>delete property is used to delete value of an array without index.
Syntax
=======
delete array[index]
Ex:
===
var arr=["HTML","CSS","JS"]
delete arr[2]
alert(arr)//["HTML","CSS",""]
alert(arr.length)//3

-----------------------------------------------------------------------------------
----------------------=====================
toString()
---------------
to string function is used to convert an array into string seperated by comma.
Syntax
----------
array.toString()
Ex:
-----
var arr=["HTML","CSS","JS"]
var x=arr.toString()
document.write(x)//HTML,CSS,JS
var arr1=x.split(",")//["HTML","CSS","JS"]
===============================================================================
Flat()
------
flat function is used to convert multi-dimensional array into single array.
Syntax
----------
array.flat()
--------------------------------
vare arr=["Rohit","CS",["Lucknow","226022"]]
alert(arr[0])//ROHIT
alert(arr[1])//CS
alert(arr[2])//["Lucknow" ,"226022"]
alert(arr[2][0])//"Lucknow"
alert(arr[2][1])//"226022"
============================================================================
find ()
========
=>find function is used to return first element of an array that satisfy the
condition .
Syntax:
=======
var x=array.find(function(data,i ,arr){
return condition
})
Example:
========
var arr=["RAM","ROHAN","MOHAN"]
var x=arr.find(function (data){
return data[0]=="R"
})//"RAM"
=================================================================
findIndex()
=======
findIndex function is use to return index of first element of an array that
satisfy the condition .
Syntax:
====
var x=array.findIndex(function (data,i,arr){
return condition
})
Example:
========
var arr=["RAM","ROHAN","MOHAN"]
var x=arr.findIndex(function (data){
return data[0]=="R"
})//0
=======================================================================
var arr=[1,2,3,4,5,6]
var sum=0;
arr.forEach(function(data){
sum=sum+data
})
alert(sum)
=================================================================
reduce function
=====
It is used to used to convert items of an array into single value by applying some
logics.
Syntax
=====
array.reduce(function(x,data,i,arr){
})
x=>inital value/previously return value .
data=>current data starting from second index.
Ex
====
var arr=[1,2,3,4,5,6]
var y=arr.reduce(function(x,data,i,arr){
return x+data
})//21
======================================================================
Concate function
-----------------------
concate() is used to merge multiple array into single array.
==========================================================================
How to change value of key
=====================
object.key="value"
object[key]=value
Ex:
===
var obj={1:"Mohan",2:"IT"}
obj[1]="Ajay"
document.write(obj[1])//Ajay
============================================================================
How to add new key/value in a object
=====================
object.key=value
object[key]=value

-----------------------------------------------------------------------------------
------------------------------------------------------------------
obj[3]="Lucknow"
obj["salary"]=5000
========================================================================
In object value can be duplicate but key can't be duplicate.If we are trying to
duplicate key then value will be replaced with new value of key.
Ex
===
var obj={name:"Rohan",branch:"CSE",salary:10000,name:"Ajay"}
document.write(obj.name)//AJAY
=============================================================================
Object is a collection of property and method.
var obj={
name:"Rohit",salary:5000,
demo:function(){
alert("Hello I am from obj object present in demo function")
}
}
document.write(`
name:${obj.name}
salary:${obj.salary}
`)
obj.demo()//Hello I am from obj object present in demo function
==================================================================================
var obj1={name:"Rohan",branch:"CSE",salary:"10000"}
var obj2={city:"Lucknow",Mobile:4895479469}
myfun:()=>{
document.write(`
name:${obj1.name}<br/>
branch:${obj1.branch}<br/>
salary:${obj1.salary}<br/>
`)
}
}obj2.myfun()
document.write(`
City:${obj2.city}
Mobile:${obj2.mobile}
`)
====================================================================
var arr=[{},{},{},{}]
=====================
var studentInfo=[
{Name:"Rohan",branch:"CSE",city:"Lucknow",mobile:487578497},
{Name:"Rita",branch:"EE",city:"Kanpur",mobile:4875784546},
{Name:"Rohit",branch:"IT",city:"Delhi",mobile:48757453454},
{Name:"Reena",branch:"ME",city:"Mirzapur",mobile:3543578497},
{Name:"Raja",branch:"CE",city:"Lucknow",mobile:987578497},
]

You might also like