Javascript notes.pdf

5,514 views 50 slides Aug 07, 2023
Slide 1
Slide 1 of 50
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50

About This Presentation

Notes


Slide Content

2} = In: 199514 À Netscape (browser) pho=
¿ata named Brandan Eich develobed a

nm user

ee z
second name =- LiveScnifst

At +hot time Jova 18 ee ae

[ale puabose Live Sont
tly inte ete
I x

apt both ane.

ll different pro; jamming Langua, Ben:

_ Common . Y de

= Mocho =>. liveScript >. Tauascaipt

Tn 1002, +hene is another -Gamous browser +hot

| wias internet Exhlonen_ Lniiennsggt browser)
a. wen copied jovaScaibt Jeatuñts made

En 05 Tscaipt

Ns intranet explonts)

ce di
_|___“Titeanet Exblonen > scale —

[EemaInteanational = Ecma inbanational is

| an industay association Founded in laas,

dedicated “to the standardization o-

infosmation and. communication Systems.

TasnSenibt + + Ecma > Bema Stnibts -
(Rules)

Problems Anlved “= We oe Scaibti >

4 OA Jon. diferent browser .

Fist | Script.

Est > lago pedis
ESAS 2004. Uinta.a? mejo dect)

Ese CES 2015) > 2015 Biggest update jun Is)
Es¢ is also known as Nodean JavaScupt

ane ol trchwidad Commgnity knash

as Te.a4 had decided iS ten 2018. nie

release javascript with hem feotuns ley

hes : —@ programmed gl a

— i y ee Onagranmen pido

= a object we Jangu
|| Back word ee a 8 ids

Variables stones the data which

| Can be changed on. used when me need.
These año - RO: to declasr a
Variable. _

{ke ion ola pe pc ane in in
a en on en EA 3

* || Var vas name =103
2 tet 1er name = 105 —
DRE pane pia ara

ae == ae

Dataty ber in TavaSes ip

There ore tusn types 9) Data
| Paimitive :
Non= primitive

| Paimitive dat 12
Almitive eya Oak.

Number:
| null

oz @ programmer

| oat

Undefined

int x

Hess

Nan- Phlmitive —datatapes aus

Object — "

Al coment sting de Élus

MIE the pulse CA: began the stag

Fos Exomble t= 00
let sty = ta;

Ss a Console Log Hype Cestad);

| Convest numbe2 into Stalin
—¡ Add a u Bun) with the number’
| Ena Esomples= : suelo

—— det num= lo;

— avaScaikt String.

-|stsing:= String ant used to: store textual

= | Jour de Jike word, sentence. TE
à ee based. indexing

== Let ta =" pro”
ER ee Ut stn = “pro;
Ru ns

E | a
E I muasenibt ssi Method

|| taime) Slice) _
| chan atO tostningt
| tomcat) Substning C)
|| index 00 — 2 Enf liees

| tastTndexo3 0 tolomer Case O)

1

TE En Undefined in Tawscaipt-

PS on..uninikialized variable returns

‘Lit tas tte ©

meta (sta); undefined
| Necreaing = none i aa pacbenty $ on object

returns |

a a__put- of - bounds gite element

Actunns undefined 0

null means ‘no value’ assign + variable.

| typeognull aetuans..‘ object?

Null is treated as False value. 2”)

ps pe

ona Small Bin tat

Fe Big Tnt_ ig a Primitive Dotatube

| which ía used For lange numeric Values

Zool dale 958-4:

it doesn't Acbnesent decimal values.
| TH 18 used 40 Acpaesent values opa tos

Fi Rp the end of numeric

_ Vas hum= 9876543 219865252442N5

ll

ETS Pas an argument =
ne ss er

en RTE

Vor bum=- E [as+ 65432198 6525279);

O @pacqsammer gal

u Teanany Operator

Tt is also called conditional

4 obenadon

Tt takes +hase olenands

TE makes the Code moho conciso.

@ prigsammen-gi xl
a aint

vañiableName = Conditim ? True: False y

T} the Condition is tue expaession after ?.
will executes. Tp it is false, expression after
> (colon) will executes u

@ rares = gl -
Wettoge = 123
let warning;

Ei agers 13 © “(warning = © You con play”)
a + Ciañhing= “6 You Cannot Play”);

Consale.Loep fanion 2

AS You. can Play : Le

E Boolean Data Type

Boolean; bac de end only up values.

Aue and falao.

Fox Exomple=
Nas Read = Bu; tulbeof(Read y,
Non Eot= False; Boolean

Prine tales Asn Come as à aault of

Comb aais ons.
Fox Examble:- ___ @ programmer —

Vos X21 ,b=4 ;

console. Leg (za) Louthut

an eee by )

= (Double men A = Known as +e
8. abstract Compasison obmatns

It Combare variables ignores. datatype.

== Tniple equals oberatos.) <= Known as the
Combarisan ojpenaton .
oro Variables as well_datatype.

FA —Tauthy and. Falay Values

Tt iso value thot is considered

“nue when encountered in a Boolean Context

Example :-
typ, $4,079,425 to", K pulse‘,

new Date), =42, 125 3.14, -3.14,

AA —Tnfinity , fer

a programmes qi
L Tr is a value that is considentd
(ils ben encountered in a Boolean context
| Example-== jh =

un

Undefined » nulls FA false, >

0, -0, on (Bigrub)

Vas values = 424 ee

if (values) E

222 Console De. 3 Me

RENTE Buta

—+ u Se =

Console. Log (Jalse);- u

Hut nun à 4

Control Elow

Dcartsobeoux Te allows ous progam to
make decisions about what code 18 executed

___! and when ar nl

AAA
EN
ya
N
N

| ER Im
RN
ie an, is it ie pont osdes ]
Jed inte Bt? 7

i Oran ojal.
Control Flow have two ty ber of Statements
— Ay Conditional Statements”

1 ehe Statements

A

t= Conditional stotements

| año basically, checks +o sec if a certain
condition 1% eithes true on false: TP the

| condition is true then Aun code Ay if its

false then und code 8.

Hangs 8

V yes Ca

ie Statements > Tfelse, äplelse if

Switch ne

:- To perfesm sobetitive task

with fess code.

a — Suite Statement

de exluntes am exp

Combase. ita fault with case values and Dee

| the Statement associated with the matching Cage

ie Susitch Cexpaession) 7

TN te

eu of cases.

breaks ~

| Casevalue 2: - @pnagsammer zur

mec ef Casez __

Er ela

{bods of default 3

o res A +o end

—the Set Switch statement.

- — play dene ahi ee

iA optional

1.4 est

Fon. Loop

= fom York executes a black of code
as Song as a sbeciPied Condition is true

psy na @ptrasammen-otnl
| fon initializer s Cond tian 5. ite
T
I stotemencts
Il 3
> | Intializent:- T+ is oh expression Hal initialize
the Loop executed once -
? || conditiom:- Tt iso boolean expression. that
+ determines whether the Jon fools should
execute on Sols.
|
> | THeroton:- Fon statement executes the. iterotor
„after each iterotion.
|
4 =
24 ede a 4
pe o font Wh ie 2; (244 41) E
| — Congole- Lg (D Fa:

While ‚Da tihile fobs

tahibes tools t= While loop executes Stotements
Da Nong as he" Conditions On. tue. Tf the

——| Condition become false „the Lonh is terminated.
De 3 while Condition) Y
aes U statements

__|Daswhillenbosb< Tn Do while loop the block
of cade. executed once euen before ganz,

+he Condition.

do Y E
statements
3 while (condition) EN

Goran

ss @ paogsamne gin!

A JavaScript Funckions

Eindtionz- A function isa black of code that

het task.

DER

—function_funName U) X
= _Jkstotements

Eee is declamd using the function

heat: Function la

= N BE.
Br: % a

function funName OF

Statements

5 nue
funNome 053 Call Function

| example — 2 ee ta

LIRE —_——funckion_mylame Of > Declane Fun-

a Console. se il ODE
| royNeme ()3 > Function call
output: Srily

| Easy +o understand

Eunchion Aiyumatss- When we «declare function
ne. res the parameters sé

A nes FT me cal Function

ine Speci the nie) uments .

Poe Exomples —

Function example. Posameten E

Console. Lg (Parameter);
i

let ongument = ‘ang’;

example aa) >

[E ecu”,

Papin is ended colle ction o oft items,

eerement | item

Index, > ©

STauaSenipbatnaayi characteristics _

T+ Can. hold values of mixed types.

ize 4 is dynamic.

14 @pnags a

Co) Cpets)
A pg

Let aaa = Ely 253 cot]; > Mixed Type
_pets. push | CO Mon key 2), À programe Size

| Annays ane 72n0-based. indexed. En means
A the. APN of << oy at

l'index Zeso.

tet pets =D Era etn 5

oe 01); > festin element

output = Cat

Le = fn) Methods :-

Dep It actuans the. number elements

in_an anna.
let num = C1, 2,°3, u];
Console. La (num. dength); Lu

a2 + Ray PushO) T+ adds elaments +o the

end of he ansay.

4
et num = Ci,2,31;
Console -Jog ( num. push (4);
o un

a Pinay Papo; Te nemaves the last element

—— from an eine and nstusns femaved
Ber clement.

am (et num [15,2,3,4)

Let #emovednum = _hum.popt);

= Console. log (num); 1} £15253)
ee at OR la Chemovednum); II.

Dra Sipe = Tt aemoves the fisst element ©

and netusns removed element
— from an et :
tet num = [12:5,uJ5 >
(et nemovednum = _hum.shift();
Console -Lo m); {1 2,3,41
me console. dog Loemouednum)s EN
| @pnogrammer -ginl-.
+ adds: elements to the
Suche beginni: 2) on aaa
let num = 01,252,475
log (num -unshiftCo));
il To,1,2,3,41

Li Array Sant) io TH Aosta the items of anos

let hum = [0,254,175 EM
| Console dog (num-sontt)),;
SES) A COB

_—A Anna nevease O i= Tt netuans the neverse
+ items of an i
0% mil) 25450 |
__Console fog ( num, neverse ());
= | Pres,

PEN = fuimitive Vs Ketenence Types.

J Paimittve Types Refenence Types |

= |
| | Tt has a dixed Size | Do not have a tixed

2120. in ay

object stoned in the |

heab.

Stoned in the variable |
Locotion is à Pointe

| Fos Examble:- Null; Eva Example :- Annaus,

Sining, Number ; Bool Objects, Functions ».

undefined ¿Symbol Dates

we cannot add,delete| he can add ‚delete

| dota.

update in primitive | update in reference
dato.

: |

Spread Operator

[Spaoadopesatos :- Tt is used 40 expand os

Ispread-an-itesable os an array. Tt is dencted

y 2 APA CRA

Si Sa” tr Lady 68, 60) 7;

Console os CansStn); 11 Céat,£Q’, fc? 1
2 onsale Log (+. OnnSts); 11 ABC

| ef ana = Ci,2,3];

let -anaz = Lu. 0311
Console.) e op paolo

Console feo Casa 2); 11 01,22)

7} ILobbend an item +o the +
+ 5%1,push Cu),
Consnle-bop Larra); 11 Ci2,3,47

Congale „dag Coss2)s 11 [y2,5J

sing

used +o assign

distinct variables. Y

a 2 Const items = C Books! , Pen” nil” J;
const: Coty p21 items > destnuctuning

3 21 Console. logica); Il Books >

+ Console, log (y); 11 Pen

if << I Pencil

= @p: psammen ain

= ¿ Const Cor, «47 = items
fin Cansole-Leg 00) Books

_ Console. day Cy). IE ‘Pen’, Pencil’)
Note:- We Should use variable with spread
= bee Syntax an the last variable otherniis

Ce. it thao. exñoh.

= T don't like emos! Do you...
Const Ley Il eos

zz zz

jects Intnoduction _

21 They ame ae fem ence type

| objects ane goed. to handle neal woxtd data,
objects Stones © data in key value pais.
21 objects don't have index.
ce a que
object declasotion:= -
O che pero ie à, à
<= home. * Coden’, > value
zu key e tne ‚ion.
an rito Console.Log Gpo person); ll object

>| Access dato...
pe Console Log ( peñson.natne) ; Il toder

Console tog. ( peasoniage); Il zo __

Aisne El det notation

Add key-value pain to objects

= | = pensons id = 5;

—— Console. log ( persoh)};

É u U name: coder”, age: 20, id: s 3

Bruta cad Annckennratien

Const pernson= Y

E — nome Coden? 3

“person age: 223
4

fey aid as a_stg by default.
Let? access’ data by PP

——Lonsole. pau D ‘name” 1);
IL output =

PSE] 3

Tn above example there ts o key named aa

“pessen age” el access it 10 dot Notation

| dot Nototion= Console leg pesson. rason age);
pa = Pre ek e#hon Be hot
include = between name.

Baacket Notabion:= Ed lan persons peson agé yD

Tt wonks because it Ÿ

le no.

paper gil SES —

nn :
Je a a,

=I + last name + Pe
ne | age: 2 (O prog samme. a
NN y
gee tote ke in. His pay era
= en u A outbut:- firstname
ANTE aceenes S44 S lastname.
a BUS | ir ee.
| Console . tg qosint se) U autbut:
U Tt access 1} progsammes
209 5015 gi
ell cme
a ” ,_peason Cee),

Tt access U 2 output: ise

AA „2 Inatname: al
— à

A Fa

3 This method war introduced
_ lin Est. TE takes an object and artusns

On_anhoy xf the. object properties. (key)

—|| Epa. Examble :—

= a Consale “log Cobject keys ( pesson));
Be lo viele

CS erartname”, € Dastname’, “age”
> 3

Object. values) :- It takes an object and
— | Aetuans an ca e A object Valuer.

Eos FT 2 engine gal. =
= __Consol ES values (pesson);

E en
ce , aint? 6719]
PR a 21

—|lObjectuentales O :- Tt takes an object and
e Aetusns the key- Value pain: es

— nb de te
the eg Cot. center ied person);

ee ORAR

= Tt assigns properties

ofan object to individual vaniables.

on age -
= Pacgtammer-ginl--

let name = pesson.name ;

EA ape ao =.

ee

ps dntifita ns © _
+ Y name, age 3 = person 5

—Conadde dog (name); Il ‘Codes! —

pe: El Logs 4

s ny Class= € 2% = ponson

= pa in
consobe.tog class) J) 6
No class Rupee person object ‚Then

1 RE Da ae he class.

_ Aso Function *— Another way do white a function

Tt is Tntnoduced in the ESG version of Ts

| THs Syntax la Ahortes +han Aequlas Function
Y

—__|}Example:- —— Function Exbxession
let add = function (a,b)?
ae ——— —feeduan ath;
KA E
Abpve Codo perds arrow function
let Madd = Coy dt
setusn ty 5,
| iC ee nn + à
—| [Function "with, -pokametes’ —___
pee (pa) > 3 statements? 11 Syntax 4.
i pi > { Stotements A Il ss Ered

A ae me quete

tas Opt I aye

Aetuxn

Capa gal

ee

A ——
ses

= T+ is a behavior. in which a function
los a Variable can be used before declaration

en.) name); ILundepinedl
Ha var name = SE ey zits,
[tt dont Cause on enzor. Because it looks
{| like in execution phase+-
Ele Nan: name, Gpsspaonmer- gil =
= a orme
Nor name= ‘x; yes
„In cose ef let key: y
—|____Console tag (names 11 Reference Essos
I. Fig Nowe Kaya”
: | Tt cause on efron - Tn Case of (ets Variable
— is 12 hoisted but not initialized.
In case. of eel kedo

— Console Log name); I) Ennor
— Const hame = xu 27;
— Conelusion:- (et and const variables ane hoisted
Rule Cannot be acceased before +heis declaratiin

Function can be called be

———fame (); > Function called

Declaration & Junction name O Y

ie Console. Log ( © a 0g xamrnes

Ps i> h
out :=_prapsommes.pislan

TypeEnsos. occuxá in cas of

caer expression ae

E A > Eunetion- Expaeäsion
Var name = function()T

console le fe pan gaacomes
a J

name C); U Tybe Ens on
Vas hame=()=> ?

Console „gg (‘programmer girl’);
Br

“Conclusion: TauaScaibt: doraht hoist the function
expressions and arrow functions.

ent ahe -

Haxical Scope:= "It means thot a variable defined
—| Outside a function Can be accessible inside
(another function defined after the variable
declasotion. But the cbbosite is not true.

dao boat re add Or
— Vor x= u, am ig hot accessible
cin au ICT ÉRMRS
ti x is accessible he, y 1s Ne
function minus O) x
Nas = 65 > ia accessible

| nf A

= Bk @pregrammertaini -

1 a Ge a

| niotes= he variable. defined. inside. a qunction_—#®
will not be accessible outside the function

In above : code. ia not accesaible

ea tiers tt er the function. __

Block Scobe vs Function Scabe

Block Scobe

Eünchian"Seope.

Tt means that the
Variable is accessible

| within +he block I }.

1 I+ means thot the
| Vamables ane onl,
accessible in the ~

pue

let and Const aro.

function in which
thes ono declared

Nos. is a Function

block Scope- Seche.
| Fon Example Fon Eyample~
fon Cletizo3 (co; i428 | Function fun O Y
11 Block von = 425
& 1 i
Console! itu TT de
| we ane trying to Consele-lo
„access let “variable We. Cannot access var
L outside the Scope. outside the function Scobe] |

Default Pamea- Tt allows us to give default
= pa A Pañametens if no values

Default parametas

a He
ECN artuxn =
| gs

Console. Dog (add t3,u)); 117

a console. Ag Cadet 53); ILX2S,4=22 4
ps - RETA (add (3); Jet, 42293

no: à parameter has A value is undefined

Er Exomble:- holies
“function add oot 1107

"AR Console. La ae
| ee _

Y rl = imi
ail Organ ag

|

Westiftnaemetenas u ia used to gathes parametens

and put them oll_in an asno.

Let's understand with an exomple:=

— function test
Eh — console. Log Ca; lie > outbut
= ° Console dog CH); ia > output
— E 4
DU el tus CS; a);

- testa, 4,4, 6,55
What vill habben with 4, 6,57 2 oobs Nothing
To Cover 3,65 (Rest parametzsa Concept Canes)

Sind ale pus Rest parameter

function test (a, i na,
Aa 11. conaslestan la);
= Console Leg Bd: _

2 RENE

+ dests,a,4,6,5);

{output = 8

8 Couple. of Spec fie

past BR pass os on.-parameter to the

oo. ‚not in_entins object.

—— > Const uses =Y
43 “name? : ‘Alex’,

Ss ur +: {sx QE ali 70? Parom.
— APP 2 det
A O usendetaids ( Lhame, gaed)
Bu nei x
aber Console bo,
raole . La Ca
| CS DS
| = rn —
| —_userdetaits( 9; a
LEA Ed tandis si
| E Alex Re
= Ant sr

L “CallBack Function

Lcallbock function:= Tt is defined as, we can alsn

Boss a function as an exce too function.

Y pinction Second (name?
Console og (name);
__Piunetion_finkt ( callback) E

callback ( nlex’);
3

lin... Hast (Second); || output: Alex

| Second Function that is passed as an argument
inside inst function is called à callbèck

Junction. _

= (notes The callback function is helpgul then
you. have to wait. for a seault thot

takes time. =

3 — Jens -
| <toneso DION of unique values _
No_index-hased access

| A antd——
_ [sets one itenable — de
seta have its mon methods.

let items = new set);

a rT
ee Se oe i

Any un eta 2

ad

Object

Can—hawe. dect values nenn Beta

Cannot. pela
«Th Bil la “padined by tnd Whereas
—tilssets tOhnnot oo ais à. 1

Const itema= new Set (5

add ©} :- Apbend a. new element to the end
of the set
Fos Exambleï= items. add (“mi”);

| I outhut = Set (1) Y ui}

.

iclens ©): Remove. all the elements and hetusns
ined.
os Examble:- Const items = new Set (Ci, 2,21);

items. clear 0);
output Set Lo) £3

delete CYi- Tt delete a Specific element Aaom
+ ER mi =

Fos. Examble:- Conat items = new Set (11,298,413

itemaidelete (3);
output Setrst 112,47

[host check Whether an element exists in
Sets op not. __ tes
items. hoa (2); lloutputi- tue.

ss maps A Mab is -a collection okey =Valuz paisa,

Similar to on object.

Const penton = new Mahl);

Las ot med. mob 2 ie base object

À Map ig Similas to ob in_objects ase

ao Te Sumbels But we Can Es

> aa Key Tn ll

nahe

Const paso = nun. 35 1

_|_peason-set (Name?) Alex);

Zar oe) RA A as

D | hotte € nome” > “alex? 2 aman
I

E 2. > i Sem =

|

pete = Retuaned the value associated with
Ed the key

lléstO):— Set the value of the key and returns

| — the mah.

à (deletst:= Delete the entay which has the:key

Same as passed. Kor

1

ai. - Delete all value pairs from
= the mab. $e a

hasc)“- Retusns true if the mab has the.
key provided.

Et ae the new iterator that
Containes the Keys insertion pader

a

SS Const pesann= 3

(dicas .
Method _& about : function O€

Name: “6 alex”,
age. 621,

Console. (og (“My name is
$i this-namet”);
2 me 2

_ ME = re — >

| outbut 2 EL nameis alex

then declaiog_a new object „use the object
Litenal , not “the new object C) Constructor.

@pacgaammr-ginden —

ra “this” Key wocad sogens o an
object thot 18 executr ¿

9 He cuasent

= piece ef code.

Fon Example
2 ——fünetion Info) E
I NR Be 18 $2 this.

== homer);

MT i

Const pessom = T ERP +
ee __ name: “codes”, ons
Be dao Ti ne

Be ia rn a =

— Const person 22?
—hame =

about: Info.
Fe: at

=> pessont.abaut(); > pessoni name.
== personz, about); > personz home.
— Il outbut:- my name is codes

FRE i myname. is ail.

calli: T+ inuokes 4he function and alfous you

A one. by one.

= jokes the Function and alas

!4o pass in arguments as on De

+ land T4 nets a new functions allowing

| +o bass ino this amar and on nd.

Const uses
name: 6Alex?;

Eads! 4 ai 214 Bpnegsammer. se
E PA ¿Junction A

ansehe ug HUES I. ORSAY
a a re A
e Y
Const opio
names ‘Thon’, Iloutput:-

Els athe ae 33 a Thon, 31
Userd. intno- call Cuser 2);

Var user? = F hom

= aoe 3
Si function Jay m
Console - It 4 +his name);
HE r

80, -abh (use 2, LH

— li Sutbut = Hi then

beta Example: cae

Var usirt = Tname : CAlex?,
age .21 34 Z BE
var ugen 2 = name: © Thon’,

function li Js.
EY —Consoba big | s. hame , this.aged)
ER y

van smpfun = Any. bind (user 1) ;

ae AS ar

may fun 2);
sal ae SA live

ae a pa =

5 Tt is used +o add new properties
= | ond methods to an Fe Object Constructor
Oe See si à @progdammes aint.

Junction Person OT _—
2! this, name= ‘Tobin’? «
His. ae = 23

A pensoh à Os
de Console . ls (Person. en

value

oil checking the phosaly

a |_paopenties ods {nom a prototype

| bsin a fasten object

2 en since “propentizs | methods on
the prototype dort have 40 be po-cacated
| each time “a new object is created.

Re teen des

Arie things o Ho _semember about nen keyword

are contes ._hew object, The ae
| object is sx u

2, || TE sitet +his hem objects internal.

| Tt makes +he this naïabte ere to Fr.

cavated object =)
a ca bj

MITE executes the Constructor function using
|| the newhy cwoted object whenever this —
ar

8 mentioned.

ee

STE petusna He newly capoted object.

a=

Bae en Herp tearing |
Keob coding |

How de yu geal lan A

en = ones nn

NE pregeamneqil-
Tags