- [Instructor] In this video…we'll look at one more quite terse, if construct,…which is called the ternary operator…or the conditional operator.…I'm going to copy this block and bring it over into Chrome.…So this is that conditional operator in action.…It's an expression, followed by a question mark,…followed by some other expression,…which is what you want to happen…when this expression is true, then a colon,…and what you want to happen with this is false.…Let's try executing this.…
Because the animal is a cat, I check whether it was true,…and if so, I do what appears between the question mark…and the colon.…If the animal were a dog,…I would do what appears after the colon,…ignoring what is between the question mark and the colon.…The ternary operator is often used to set a variable,…based on certain conditions.…Here's a line that does that.…We're going to copy the whole thing and bring it over.…
So having executed this, animal is a cat.…Here's my console message right here from this first block…and then I set the job variable based on the same condition,…
- Using a text editor
- Declaring and assigning variables
- Booleans and the quest for truth
- Working with objects and arrays
- Using operators and control structures
- Iterating with loops
- Objects, references, and functions
- Promises, async, and await
Skill Level Beginner
1. Getting Started
2. Variables and Types
3. Objects, Arrays, and More
4. Operators and Control Structures
5. Iterating with Loops
7. More Advanced Pieces
Next steps3m 38s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.