From the course: Mastering Web Developer Interview Code

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Do you know how to use the conditional operator?

Do you know how to use the conditional operator?

From the course: Mastering Web Developer Interview Code

Do you know how to use the conditional operator?

- [Instructor] The conditional operator is a different version of the regular conditional expression in JavaScript. It's something that you'll probably see in a lot of code and it may come up during some interview questions. So, let's take a look at what it looks like and what it does. So here we have an example of a conditional operator right here and then right underneath, the alternative, or normal way of writing this. The conditional operator is the only JavaScript operator that takes three operands and that's why it's also known as the ternary operator. So it's a shortcut for the conditional expression, which is the if then else expression that's commonly used in JavaScript. Now, this conditional operator is also chainable, so you can use another ternary operation right here in this true expression and even another one in this false expression. But that's one of the problems with it. You can see that it is…

Contents