var truth = true;
(truth) ? console.log('It is true') : throw new Error('It is not true');
Do ternary operators only accept specific types of objects?
The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark ( ? ), then an expression to execute if the condition is truthy followed by a colon ( : ), and finally the expression to execute if the condition is falsy.
Except in very simple cases, you should discourage the use of nested ternary operators. It makes the code harder to read because, indirectly, your eyes scan the code vertically.
The correct answer to this question “Which of the following is not considered a JavaScript operator” is option (b). this. Other than “this” all the other options are the JavaScript operators.
?: = Question Mark Colon is also called C Ternary Operator.
javascript distinguishes between statements and expressions. The ternary operator only handles expressions; throw is a statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With