Um I currentlyliveinSTLouisworkingas a salesforcedeveloper.
X columnconsulting.
So I'm inthisoneofthoseofficewerealloverthecountryallovertheworld.
And I am a proudcatMomoftwo.
So I wanttostartwith a story.
Onceupon a time, therewas a juniordeaththatwasgiventhetaskofintegratingstripepaymentswithSalesforceusingJavaScriptandsellsforcesJavabasedproprietarylanguageApex.
So, youknow, you'reprobablythinking, whyshouldtalkingaboutallthis?
But I wantthistalktodotwothings.
One I wantedtobesomethingthatcouldbehelpfulfornewdeaths.
UnderstandJavascript a bitbetter.
Andtoshowanoverviewoverdifferentwaysthatyoucando a secretitsprogrammingwithJavascriptonand I wantit.
I basicallywrotethistalkis I wantedtobreakitdownformyself.
I wasusingsomethingthat I hadnoideawhatwashappening.
Andtwo, I wantmidcareerandseniordevelopersintheroomtorememberthatmostofthetimewedon't gettaughtthisstuffifyoudon't didn't get a C s degreeorevenifyoudid, andit's kindofconfusingandit's possibleyoutakeyourunderstandingofthisforgranted.
Butsometimesyouneedtomake a callout, requestdatafromminuteexternalsystem.
Andbecausethosethingstaketime, theycouldhold a processingofotheractionsthatareindependentofthatdatathatyouneed.
Soifyouwaitforittocomebackbeforeyougoontothenextstepin a partofyourprocessyou'rewastingpreciousresourceis, andthatcouldbeusedtodosomethingelse.
It's kindoflikedoinghouseholdchores.
Sayyouneedtocleanupyourhouseanddolaundry.
Sousually I put a loadofclothesinbefore I startcleaningtogetthatprocessgoing I don't knowabout.
Andifyou'redoingtoursin a totallysynchronousway, thiswillrequireustoputourdirtyclothesinthewasherandthenproceedtostandtherefor 30 minutesas a wash, rinseandspinbeforewecanputtheminthedryerforthenextpartoftheprocesstwohourslater, you'restillstandingthere.
Thesunisgoingdown.
Inthemeantime, I can't getanythingelsedone.
I can't moveonfromthebathroomorloadthedishwasher.
Whichleadsusto a conversationonasynchronousprogram.
Butforthiswell, Javascriptiswrittentodealwithuseruserinteractionsinrealtimeinthebrowser, sousersdon't usetheWeband a synchronousway, whichissomething I wouldhavelike, kindofliketolearnabout.
You'reinteractingover a networkconnection, pullingdatafromexternalsources.
Well, sometimes I havemyhairand, like, protectthestyleslikethisbraidsright?
Or I have a frozen.
Itstayslikethat.
So I'm notcalmingmyhaireveryday.
So I havetoputsomeconditionerinoilinmyhairfirstandletitsitsomyhaircangetsoft.
Andthen I couldgoonto d tanglingrightlikesoft.
And I couldgetthoseshedtears, I couldtangleit, andthen I'llgoaheadandshampoomyhair, rinsethatstuffout, andthen I havetodoconditionbecause I haveto, youknow, putthemoisturebackin, letthatsitforawhile, rinseitout, andthenairdryairdryingofftakestimeandthewholeresearch I wouldturnmystyledhairandthisiswhatmySaturdayJimmylookslike.
So I hadmychoicehereusingmyhairdolaundry, cleanlitterboxesgointhekitcheninthebathroom.
Soif I didthissynchronouslyinorder.
Itwouldtake a longtimesince.
Lookatthis.
Thisiswhatmydaywouldlooklike, right?
I'd have I dohere, um, functionhereand I havetogothroughallthatbefore I actuallygottoAnythingelseinmydoCharlesfunction, and I'm gonnagointodetail, so I getfreetreatmentrequiresmetoputconditionalonmyhair.
Anddowhat?
Waitright.
So I havetoletitsitbefore I goontotangle.
So I'm waiting, andthen I haveanotherasynchronousprocesswithinDohereagain, right?
I havetodeepconditionmyhair.
Letusitwait.
Andthen I havetogoaheadanddoanotherasynchronousprocess, whichisairdryingmyhair.
And I havetowait, andthattakesevenmoretime.
Solookingatthedochoresfunctionagainhere I havethreeasynchronousprocesses, anditwouldtakeforeverbefore I starteddoinganythingelsecleaningthelab, youknow, cleanthelittleboxes, doinglaundry, anyofthat.
Sothere's gottobe a betterwaytodothis, right?
AndthereisThanks.
JavaScript.
Let's doit a synchronouslywithgobacks.
Sowhatis a callback?
Callbackis a functionthatispastasanargumenttoit, a secretdysfunction.
I eat a functionittakes a whiletocompletesometime.
Umandthisfunctionwouldbeconsidered a blockingoperation.
Youknow, youcan't goonanddoanythingelseinthedohairfunction, but I alsocan't doanythingelseinmyoverallTaurusfunction.
Um, so I haveto I'm gonnagoaheadandrewritethisas a callbackthatway.
Wedon't getstuckhere.
Nope, Sorry.
So I have I haveittaking a callback.
Let's lookatit.
So I havethisfunctionhereiswe'vewrittenis, ah, a functionthattakes a callbackandwe'lllookatitinmoredetailfromthispoint.
Sohereismyprepoofunctiondeclarationindicatesthat I amgonnahave a functionthattakes a callback.
Andsothiswasmypeople.
Treatmentdoesright.
Mostofthefunctiondoesthatputconditioningoilmyhairand I wait.
Anduponcompletionoftheaforementionedprocessofputtingtheconditionalinmyhair, I willcausethattimeout, whichis a methodthatwillcall a functionwhichinthiscase, isourcallbackafter a waitingperiodandnow I'm gonnagoaheadandactuallycallthepeopletreatment.
But I'm goingtogoaheadandpassinmyfunction, whichinthiscaseisananonymousfunctionthatcontainstherestofthenaturalhairprocess.
And I'veabbreviatedhere, butyoucanseethatjustforclaritysake, that's whatpassedinnowyoucanalsoinStansheatethecallbackfunctionandsaid, equaltoe a variableandpassingmyreferencewhichwillseethisdonebothways.
Soif I have a perfectpizza, I'm gonnagoaheadandeatthatpizzaOrifit's burnttrash, I'm gonnagoaheadandthrowawaythatpizzapracticessowecanrewriteprepoolthefunctionpeopleask a functionthatreturns a promise, andthisenablesustogoaheadandcallthethingsonit.
Sohere I havepeopletreatequalthiofunctionanonymousfunctiontakeshere, returns a promise.
I'm gonnagoaheadanddetailit, shampooitandtheresolvethispromisewithshampooedhereso I cangoontothenextstepandno I couldhavedohairreturn a promise.
AndthisallowsustochangeourpromiseswithdotthinsUponcompletionofanasynchronousfunctionsprocessing, wecangoontothenextstepthatreturns a promise, whichmeansthatwecandoanotherdeathinandcompleteanotherstepintheprocessandalsonoticethatthathascomeafterthereturnofanasynchronousfunction.
Andifyou're a singer, deathtraining, a team, orsomeonethat's newtodevelopment, maybenontraditionalback, backgroundlikemyself, I wasaneducationandnotpracticebefore I cametotechagain.
Justknowthisstuffisn't always a parenttryingtorememberwhereyouwereherewhenyouwerehere.
Havesomeempathy, youknow, andshareyourknowledge.
Youknowwhattheysay?
Thosewhocanteachandthosewhocan't justsitin a cornerandcalledbythemselves.
I noneofthematerialswereanythinglikeanythingthat I hadpersonallyexperiencedandfrankly, sometimesjustmadeithardformetounderstandthecontentthat I wassupposedtobelearning.
Soit's importanttomethateveryoneseesthemselvesinthisfieldnomatterwhoyouare, itmakes a difference.
And I alwayslikedThiogivesshoutouttomyinspiration.