Console.
log is for taking inputs
And console.warn show this as warning in their console;
And console.error show this as error in their console
Alert and prompt mai bhi hum cheeje
Like alert mai cheeje bss show hogi jaise codeforces pe
show hota hai jb koi question change karna hota hai
Like promt mai alert jaise cheej hi hogi but usme jagah
rahegi humare jawab dalne ki bhi
Now we talk about primitive and reference data type
Now we learn how to transfer data with reference and
without reference
Like in this
Var arr=[4,5,45,45,3,4,6,53,];
This array is given and when we copy in some other array
than it will not copy it go with reference
Var b=arr;
This is b contain reference of arr so when we perform
any operation on n it will affect arr also
But bro it look like copying ……………haa it look like
but it is no
So bhai jab copy karna ho data tab
Var b= […arr];
… three dot for spread after applying three dotwrite
any var name it will copy this int ba
Types of function
Es5 and es 6
Es5 is divided int three types
1) Function statement
2) Function expression
3) Anonymous function
Es6 contain fat arrow function
But can be written in three ways
a) Basic fat arrow
b) Fat arrow with one param
c) Fat arrow with implitcit return
d)
Function bannae ke liye type nhi batana padhta
Use koi nam deke bna skte hai
Bss use phele function key word likhna padega
,
Iss wale type mai function ke pass nam nhi rehta
haii
Fat arrow funciition ko kisii var maii strore bbhi
kar skte hai aur nhii bbhii
Fat arrow ke teen type
Phele single parameter
Mai iska bracket hta skta hun
Implicit functipon maii
Bracket hta do and arrow kea age kcuh bhi likh do
Isme array mai kuch bhi dal skte hai kuch bhi
Arr.forEach(function(val){})
Object bannae ke tareekhe java scrit mai
Bhai phele global mai check kiya this ko thou ska
matlb widow tha
Fir function mai bhi window tha
Fir method mai check kiya
Bhai ye method kya hia prr -aisa function jo object
ke andar ho use method khete hai
Obj mai kisi entity mai function bna ke check kiya
Tho wo khud ka hi object aaya
Method ke andar wala function window ko refer karta
hai
Isme bhi say name ke just andar wala object ko
refer kar rha hai but childfnc ke andar wala window
ko refer kar rha hai
But es-6 mai agar mai koi method banaou uske andar
ke function mai this kahu toh wo object ko refer
karega functon big fat wala tho wo yaad rkhta hai
khud ko and wo object ko hi refer karega
Event listner mai this ki value uske upar wale ko
hi denote kar rhai hoti hai
CALL APPYL BINd
So mujhe pta hai function mai this ki value window
aati hai but mai chahta hun ki uski value window
naa aye toh mai .call ke istmal karung jo object
dalunga isme wo dikhayega ye
Jab parameter mange toh call ko kaise change
karenge bhai
APPLy mai kuch nhi jo parameter hum , ke sath de
rhe the uski jagah array ko dena hai bss simple
Bind bhi call ki tarah hai ye function ko call nhi
karta hai ye save karta toh hum isko badd mai
istmal kar skte haiA
Prototype inheritance
Agar kisi function mai maine this ka istmal kiya
aur use new se sath Rakha toh wo this wali jagh mai
ak empty object baitha dega jiki wajah se object ka
name harsh ho jayega and age =25 ho jayegi
Ye upar wali sarri khani constructor function ki hi hai
Bss ye ebaat yaad rkni hai ki constructor function mai this uss object ko denote karta hai
Isme function add kiya hai humne jo name ko print karega becoz this se matlb hia uska
object
Ab hum jab koi object banyaenge toh ye jo function hai wo hark e liye apni alga memory
istmal karega jo jayada space khygi prr hum chahte hai ki wo naa khaye jyada space ki wo
agal rhe baki log use use kare ske aur akk barr hi initialise ho memeory\
So abb maine use hta diya
Prr mai chahta hun wo hat toh jaye pr sarre human ke liye present ho usme so we use
prototype inheritance
Toh uske liye hum ak commad se kisi bhi object mai prototype add kar skte hai
Object_name.prototype.jo bhi add karna hai like
Abb hum jitni bhi objects banyenge un sabme ye chacha present hoga
Abb sbme ye function as a prototype present hoga h
Closures :
Aisa koi bhi function
jo ek aur function ko
return karde usey
closure kahte hai using
some value of parent
function ka koi
variable
Even deligation
Ki agar play ya pause pe listner nhi lagaya toh
uske parent pe check karega uspe bhi nhi mila toh
wo uske parent pe check karega mtlb body pe
Higher order function s
Try and Catch
Like jo bhi error ke box mai likha hai wo catch ke
argument mai aa jayega
Console.error like diyo console .error ki jagah wo
error ki form mai dikhayegi
EVENTS
Hum koi bhi different event bna skte hai
Asycronous java script
Soo there are two types one is synchronous
Which work of make stack
And other is asynchronous which work on side stack (or call back
queue )and first we perform task present in main stack means
task which is type of synchronous and after the main stack
become empty we transfer the task from side stack to main stack
then perfom task so from there we understand task cannot be
accomplished in side stack it need to be present in main stack
to be done
Asyncroroush(side stack ) mai processing chlti rehti ha but
answer nhi aata hai answer tab hi ayega jab wo main stack mai
ayega
Bhai pr ye sab check kon karta hai main stack khali hai yan
hi
So ye sab EVENT LOOP check karta rehta hai har time ki wo
khali hai yan hi
Jo phlee complete ho jata hai asynchronous task use main
stack mai laya jata hai
Jab mai upar di gyi cheeje likh rha hun tab mai
asynchoronous code likh raha hun
Aisa koi bhi code jismein kuchh time lagta hai , js maein
use by default in most cases async code mann kar side stack
mein daal diya jaata hai
Ye sab use hi tabhi kiye jate hai jab aisa kuch karna h
jisme time lagna ho
Settimout – iska code kuch time baad chalta hai
Setinterval-set interval ka code kuch der baad chalta hai
baar baar ek particular interval time mai ]
Fetch API- ue kisi url par jaa kar kucch data layega ya
data humaare paas se us url par leke jayega
Axios (or other HTT libraries) – ye bhi wahi karega jo
fetch karta hai bas ye thoda jaada developer friendly hai
Promise -ye janaab ke andar jo code likhoge wo apana kam
karega aur ye khud side mein chale jaayega us code ko lekar
aur jab andar se code resove kiya jayega tab ye challenge
NOW START
Settimeout
Ye ak function hai
Jo ak function ko chalyega jo time diya hai utne mili
seconds baad
Setinterval- function hai
Isme ak function hoga jo time given hai utne mili second
badd dobara dobara chalega
Interval ko rokne ke phele is kisi bhi var ,const, let mai
store karo then clearInterval kardo apka ka mdone
One more
FETCH API
Ye kisi api ko connect karta hai
Kunki ye internet par jayega ur fir data ko lekar aayega to
ismein time lagta hai to by default hi js mein fetch ko
async banaaya gaya hai kyunki fetch ka kaam hai data lana
wo bhi kisi url kse ab aisa ho ska hai us url ki webite
slow ho to data lane mein teme lage aur agar fetch
synchrounous hota to uske baad ka code tab tak nhi chalta
jab tak uska data nhi aa jata
Tho bhai fetch ke niche wala phele chal jayega ye tho
dikkat nhi ho jayegei as we need to this API before my next
command
THEn darta kyu bacha humare pass iska bhi jugad hai
Fetch (‘https://randomuser.me/api/’)
.then()
Pr bhai mann ke fetch hua hi nhi toh kya karenge hum
Tension not bro uske liye bhi jugaad hai
Badd mai dekhenge
Agar mujhe use readable format mai convert karna hai tab
Fetch an eke baad then raw jab readable mai convert ho jaye
then use dikha do
AXIOS-fetch mai do baar then lagta ahi axios mai sirf ak
baar then lagta hia
So bhai phele iski wesite pe jake cdn ka url lana hai html
wali file mai script.js ke upar save karna hai
Then use karna hai
Isme raw data nhi milta direct result milta hai
Promise
Promises kya hai?
Kuchh code socho man mein socho, jo ki async code ho, matlb
ki ye side stack mein jayega aur baad mei chalega main
stack mai ,ab ye socho ki ane is code ko likha hai to iska
Answer kabhi aayega aur aisa bhi ho skta hai kis answer naa
aye ,promises kya hai aisa samjho ki a promise ke andar koi
async code likhdo jo man mein aaye aur promise aapko ak
parchi de deta hai and wo parchi par default likha hota hai
waiting,parchi par do event hote hai mainly ek event ka nam
ha then aur ek event ka nam hai catch, agar apka data
aagaya to parchi pe completed likh jaayega waiting ki jagah
and then chalega aur agar data mein dikkat aayi to catch
chalega and waithing ki rejected likhjayega
Aman Raghav ke paas gaya aur bola ki kahana lene bhejdo
kisiko raaghav ne kisi ko bhej diya and aman ko bola ye
parchi kisiko raaghav ne kisi ko bhej diya and aman ko bola
ye parchi lelo jab bhi wo banda aajayega to parchi par pata
chal jaayega
Ye pattern toh ratna hai yaad se
But bhai hume pta kaise chalega ki konsa button daba taki
hum kam kar ske
Ye bna lo parchi ke baad .then and ,catch lagana hai
CALLBACK
Call back kcuh khaas nhi balki sirf eek function hai jisse pass
kiya gaya ho kisi aur function mein aur jab wo function chle
Aise koi function jissi call karte hai kisi aur function ko
call karte wakt aur use hum parent function mai skte hai
First phele api se data manga liya then mene then mene kha bhai
tu function tabhi chlaiyo jab result aa chuka ho use phele nhi
Yaad se
Async/Await- koi bhi function banalo and uske andar jo man mein
aaye wo async code likdo ab jab app async likhto ho to baad wali
line pahle chal jaati hai kyunki asyn side stack pe hot ahai aur
baad walli line agar async ke basis par hui to apka code fail ho
jaayega wo isliye kyunki apka code depend karta hai async code
par jo ke baad mein chalega sync code chale ke baad
Agar app chahte ho ki fetech ke anne tak uske niche wala na
chalet oh fetch ke phele await likhna padega aur function ke
phele async likhna padega
EVENT LOOP
Even loop check karta hai ki Main stack khali hai yaa nhi call
back queue ke bheje yan hi
Q ek url se data lekar aao and usey console par show karo
GENERATORS – iske through hum koi bhi code ko pause kar skte hai
Function ke baad * likhna hai
Pheli baar next() likhunga toh first yeald tk chlalega then next
tho dusri yield tak chalega fir next use agli yield tak chalega