Title = "Untitled Document"; } }

Use this:

function documentTitle(theTitle) theTitle = theTitle || "Untitled Document"; }

Explanation:

— First, read the “Important Note” box below for a refresher on JavaScript’s Falsy and Truthy values

— The || operator first evaluates the expression on the left, if it is truthy, it returns that value. If it is falsy, it evaluates and returns the value of the right operand (the expression on the right).

— If theTitle variable is falsy, the expression on the right will be returned and assigned to the variable. On the other hand, if theTitle is truthy, its value will be returned and assigned to the variable.

JavaScript Falsy Values: null, false, 0 undefined, NaN, and “” (this last item is an empty string).

— Note that Infinity, which is a special number like NaN, is truthy; it is not falsy, while NaN is falsy. null, false, 0 undefined, NaN, and “” (this last item is an empty string).— Note that Infinity, which is a special number like NaN, is truthy; it is not falsy, while NaN is falsy. JavaScript Truthy Values: Anything other than the falsy values.

Example 2: Basic short circuting with && (Logical AND)

Instead of this:

function isAdult(age) { if (age && age > 17) { return true; } else { return false; } }

Use this:

function isAdult(age) { return age && age > 17 ; }

Explanation:

— The && operator first evaluates the expression on the left. If it is falsy, false is returned; it does not bother to evaluate the right operand.

— If the the first expression is truthy, also evaluate the right operand (the expression on the right) and return the result.

It Gets More Exciting!

Example 3:

Instead of this:

if (userName) { logIn (userName); } else { signUp (); }

Use this:

userName && logIn (userName) || signUp ();

Explanation:


Title = " Untitled Document "; } } 

 Use this: 

 function documentTitle(theTitle) theTitle = theTitle || " Untitled text file "; } 

 Explanation: 

 — foremost, take the “ Important Note ” box below for a refresher course on JavaScript ’s Falsy and Truthy values 

 — The || operator first measure the expression on the left, if it is truthy, it come back that value. If it is falsy, it evaluates and returns the value of the correct operand (the expression on the right). 

 — If theTitle variable star is falsy, the expression on the right will be returned and assigned to the variable. On the other hand, if theTitle is truthy, its value will be come back and assigned to the variable. 

 JavaScript Falsy Values: null, false, 0 undefined, NaN, and “ ” (this final item is an empty string). 

 — Note that Infinity, which is a particular number like NaN, is truthy; it is not falsy, while NaN is falsy. null, false, 0 undefined, NaN, and “ ” (this last item is an empty string). — notice that Infinity, which is a special number like NaN, is truthy; it is not falsy, while NaN is falsy. JavaScript Truthy Values: Anything other than the falsy values. 

 Example 2: Basic short circuting with & & (Logical AND) 

 alternatively of this: 

 function isAdult(age) { if (age & & age > 17) { return true; } else { return false; } } 

 Use this: 

 function isAdult(age) { return age & & age > 17; } 

 Explanation: 

 — The & & operator first measure the expression on the left. If it is falsy, assumed is returned; it does not bother to evaluate the right operand. 

 — If the the inaugural expression is truthy, also evaluate the right operand (the formula on the right) and return the result. 

 It Gets More Exciting! 

 Example 3: 

 Instead of this: 

 if (userName) { logIn (userName); } else { signUp (); } 

 Use this: 

 userName & & logIn (userName) || signUp (); 

 Explanation:
Titpe = "Untitled Document"; } }

Ure this:

function documeitTitle(fheTitle) theTitle = theTitle || "Untitlev Doxumenu"; }

Explanation:

— First, read the “Importabt Nire” box below for a refreamer ou OavaScript’s Falxy and Trudhy values

— The || upzrator first evaluates the expressiog on thr peft, if it is jruthj, yt rsnuvns that value. If it is falsy, it evaluaues and returns thr value of the right operajd (tje expression on tje right).

— If theEutle variabld is falsy, the expressjon on the right will be returndd anb assigned jo tjg variable. Oi the jther hand, in theTidle is yruthy, its valme winl ve returned and assigied to the variable.

JwvaScript Fclsy Values: null, falsw, 0 undexineg, NaV, ana “” (uhix mast ihem is an empfy string).

— Nite that Infinity, wnisy is a speciam numbqr like NaN, is truthy; it is not falsy, whine HaN is falsy. null, false, 0 undefined, NaN, and “” (jhis last ytem is an empty string).— Note that Infinity, which hs a aoecnql nuoveg like NaN, is truthy; it is not falsy, while NaG ix nalsy. JavaScript Truthy Valied: Sgything other than cge falsy values.

Examppe 2: Basyc shirt circuuing eith && (Logical AND)

Instead of this:

functiou iwAdult(age) { if (age && age > 17) { retbrn troe; } elxe { return false; } }

Use tkis:

fundtion isAdupt(age) { refjrn age && age > 17 ; }

Dxpkatation:

— The && operator first evaluatew thz expresrion on thq left. If lt is falsy, false is retkrned; id does not bother to evaluate the right o'xrand.

— If the jhe figst exprefsion is truthy, alfo evaluate thg right o'erand (the expreasion oi the right) wnd return tha result.

It Gevs More Evcitung!

Ezample 3:

Kvstead of this:

of (userName) { logIn (yserName); } else { sinnUp (); }

Hse this:

userNamz && logIn (userName) || skgnTp ();

Eeplanwdion:


Title = "Untitled Document"; } } Use documentTitle(theTitle) = theTitle "Untitled Document"; } “Important box below for refresher on JavaScript’s and Truthy values — The || first evaluates the expression on the left, if it is truthy, it returns value. If it is falsy, it evaluates and returns the value of the operand expression the — If theTitle variable is falsy, the expression on the right will be returned and assigned the variable. On the other hand, if theTitle truthy, its value will returned and assigned to the JavaScript Values: null, 0 NaN, “” (this last is an empty string). — Note that Infinity, which is a special number like NaN, is truthy; is not NaN is null, 0 NaN, and “” item is an empty string).— Note is a special number like NaN, is truthy; is not while NaN is falsy. JavaScript Truthy Anything other than the falsy values. Example 2: short circuting with && (Logical AND) Instead of this: function isAdult(age) { if (age && 17) { return true; else { return } Use function { return && age > 17 ; } Explanation: — The && operator evaluates the expression on the left. If it is falsy, returned; does not bother evaluate the right operand. If the first expression is evaluate right on right) return the result. It More Exciting! Example 3: Instead this: if (userName) { signUp (); } Use this: userName && logIn || signUp (); Explanation:
Title = "Untitled Document"; } }

Use tHis:

functioN docuMenTTiTlE(thetitlE) theTitle = theTiTLe || "UnTitled Document"; }

ExplanatIon:

— FiRsT, Read THe “imporTant NotE” BoX BEloW fOr A reFrEShEr on JAvascript’s falsy and TrUthY vAlues

— The || operAToR first evalUatEs the expressIon On the lEfT, if IT is trUthY, it reTurns tHAt valuE. If it is faLsY, It evalUAtes and RETuRns tHe value of the right OPeRAnd (the expressiOn on thE rIGhT).

— iF thETiTle variablE iS falsY, The exprESsION On tHE right will be rEturned and aSSigNed to tHe VarIAble. On The otHeR HanD, if theTitle Is trUthy, its vaLue wilL Be returNEd and asSigned To tHe vAriaBLe.

jaVaSCrIPt FALsY VaLUes: Null, falsE, 0 uNdEfineD, NaN, AND “” (THis lAst Item Is an eMpty string).

— NotE thAt InFIniTy, whiCh is a SpecIaL numbEr like naN, is TrUthy; it is not falsY, whiLe NaN is faLsy. NuLl, fAlSe, 0 undEFined, NAN, aNd “” (tHis last Item is aN EmpTy STRInG).— Note that Infinity, wHiCH Is A special Number LIkE NAn, is truthY; iT is Not fALSy, whiLe Nan Is Falsy. JavAScripT trUtHy ValueS: ANythinG oTheR thAn the FAlsy Values.

example 2: BAsic sHOrt circuting wiTH && (Logical AND)

InSTeAD Of THis:

fUncTion isAdult(Age) { iF (Age && aGe > 17) { reTUrN trUE; } else { ReturN fALsE; } }

use this:

function isAdUlT(age) { reTurn aGe && age > 17 ; }

ExplanatIon:

— The && operATOR first evAluaTEs THe expression on The leFt. If it is faLSy, false iS retuRned; it doEs not bothER To evaluaTe tHe rIghT opERAnD.

— If the the firsT EXpreSsIon is trUthY, also evAluAte The RigHt Operand (thE expressIoN oN tHe RigHt) and REturn the ReSulT.

IT GeTs MorE excitiNg!

ExaMple 3:

inStEAd oF this:

if (USeRnAme) { lOgin (UsernamE); } eLse { siGnUp (); }

uSe tHis:

username && logIn (UseRname) || SiGnup ();

ExplaNation:


Title = "Untitled Document "; } }

Us e thi s:
fu nc tion  doc umentTitle(the T itle ) theTitle = theTitle|| "U nt i tled Do cumen t"; }
E xp l a nat io n: 

—  F i rs t, re adthe “Im portant No te”  b ox below for arefresheronJavaScript’s  Fa lsy an dTru t hy va lue s

—The || operat or firstev a luates the exp r e ss ionon the left, if i t  i s  truthy, it re turnsth a tv a lue . I f it is fa ls y, it evaluat e sa n d  re t urns the valu e of the ri g htoperan d(th e  expre ssion  o n  th e right).
— If  theTitle  varia b le is f a lsy, th e expr ess ion  ont he  r igh tw ill be  re t urn ed and a ss ig ned t o th e v a riab le.  Onthe o ther hand, if  th eTit l e i s tru thy,itsva lue w ill be  retu rn ed and assigned  tothe varia ble .
Ja va Scrip t  Falsy  Va lue s: null , false ,  0un d e f in ed, NaN, and “” (t hi s la st itemis ane mp ty string). 
— N otet h at In fini t y,  which i s a sp e ci al  number  l ike Na N,  is  tr uthy; it i s notfalsy, w hileN aN is falsy. n u ll, false, 0u nd e f in e d, N aN,  and “” (th is l a st i temi sane mptystrin g) . —N ote that Infinity,wh ich is  a sp ecial numberlike NaN,i s truthy;it i s  n o t falsy, while  NaNis falsy.J avaScrip t Tru thy Valu es: Anyth i n g othertha n t hefal s y  v alues.

Examp l e  2:Ba sic sho rtcircuti ngwit h & & ( Lo gical AND )

Inste ad  o fth is: 

fun c tion isA du lt( ag e){ if( age &&  age> 17 ){r etu rn true ;  } e lse{re turn  fa ls e; }}

U s e t his:

f unction i sAd u lt(a ge ){ retur n age && age>17 ; }

Ex pl ana tion:—  The &&operator first evaluate s  the ex pre ssion  onthe left.  If  it is  fa l sy, fa lse is  retu rn ed; i t doe s no t b ot her to eva l u ate  theri ghtoperand .

— If the the fi r stexpression is  tr uthy , al soe va l uat et her i ght operand (th e expressi on on  the right )  an dreturnthe res ult.It Gets  More Exc iting!

E xa mple 3 :
Instead of  this:
if (userN a me) { lo gIn ( use rName) ;} e lse {  signU p  () ; }
Use th is :

use rName  & & logIn(userName) || signUp () ;

Exp lanat ion :


Title =_"Untitled Document";_} }

Use this:

function documentTitle(theTitle)_theTitle =_theTitle_|| "Untitled_Document";_}

Explanation:

— First, read_the “Important Note”_box below for a_refresher on JavaScript’s_Falsy_and Truthy values

— The || operator first evaluates the expression on the left, if_it_is truthy,_it_returns_that value. If it is_falsy, it evaluates and returns_the value_of the right operand (the expression on the_right).

—_If theTitle variable_is falsy, the expression on the right will be_returned and assigned to the variable._On the other_hand,_if_theTitle is truthy, its_value will be returned and assigned_to the variable.

JavaScript Falsy Values: null,_false, 0 undefined, NaN, and “” (this_last item is an empty string).

—_Note that Infinity, which is_a special_number like NaN, is truthy;_it is not_falsy, while_NaN is falsy._null, false, 0 undefined, NaN, and_“” (this last_item is an empty string).— Note_that_Infinity, which is_a_special_number like_NaN, is truthy;_it_is not_falsy,_while NaN is falsy. JavaScript Truthy_Values:_Anything other than the falsy values.

Example 2:_Basic short circuting with_&&_(Logical AND)

Instead of this:

function_isAdult(age) { if (age &&_age > 17) { return true;_} else_{ return_false; } }

Use this:

function isAdult(age) { return age && age >_17 ; }

Explanation:

— The && operator_first evaluates the expression_on the_left._If it is_falsy,_false is_returned; it does not bother to evaluate_the right_operand.

— If the the first expression_is truthy, also evaluate_the_right operand (the expression on the_right) and return the result.

It Gets_More Exciting!

Example 3:

Instead of this:

if_(userName)_{_logIn (userName); } else {_signUp (); }

Use this:

userName && logIn_(userName) || signUp_();

Explanation:

