Java Script
Java Script
Isme array mai kuch bhi dal skte hai kuch bhi
Arr.forEach(function(val){})
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
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
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
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
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
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