Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Example: How to use || operator to shorten the code.

<h1>{!title ? "Click an animal for a fun fact" : title}</h1>
// This can be shortened using || operator.
<h1>{title || "Click an animal for a fun fact"}</h1>

/*
If the L.H.S evaluates to true, then it is going to use value of title, 
if it is false then code on R.H.S will be evaluated.
*/
 
PREVIOUS NEXT
Tagged: #How #operator #shorten
ADD COMMENT
Topic
Name
8+6 =