Ternary Operator | Table O Contents
The Ternary or conditional operator is the only JavaScript operator that takes three operands …
Note. The Flammarion Logo Badge
in the page header above is an .svg
image file set to the dimensions of 5%
width, auto
height, and zoom
. Go ahead and test the zoom-out
feature by hovering over the badge to engage the expansion of the image.
The Formula
Hint. Store in a constant variable …
The Code
const cartItemCount = isAuthenticatedUser ? 1 : 0;
In Action Test
const isAuthenticatedUser = true;
// const isAuthenticatedUser = false;
const cartItemCount = isAuthenticatedUser ? 1 : 0;
console.log(cartItemCount);
The Results
Returns …
1
for true
and 0
for false
Steps of the Algorithm
// Store in a constant variable named `cartItemCount` ...
// Is our subject an `authenticated user`?
// If so by placing a Boolean function upon the element ...
// Returns `true`
// Statement resolves to `1`
// Or,
// After initially placing a Boolean function upon the element ...
// Returns `false`
// Statement resolves to `0`
// Stop
Last Subtitle
More to come …
Note. The above synopsis was derived from a video lecture written, produced and performed by …
Reed Barger
: [1].
For additional reference on the topic of Ternary Operators
see the Mozilla Developer Network
: [2]
For a working Internet development platform for Javascript Ternary Operators
see Scrimba
: [3]
Support
Please support the co-workers who aggregate the Source Links for our projects.
Patreon
Like what you see in this project? If so, then support the authors and machine-elves
who aggregate the source links and pages for our projects via Patreon.