βvar truth = true; (truth) ? console.log('It is true') : throw new Error('It is not true');βββββββββββββββ
Do ternary operators use only certain types of objects?
javascript distinguishes between expressions and expressions. The ternary operator processes only expressions; throw is a statement.
It works, but the problem is with the throw expression in the else branch.
Using
(truth) ? console.log('It is true') : (function(){throw 'It is not true'}());
The conditional operator, like all other operators, can only be used with expressions.
throw x; is an expression, not an expression.
throw x;
Source: https://habr.com/ru/post/1447613/More articles:MySQL update value using maximum date - sqlIs it possible to access another address space to access a specific instance of the object? - c #Import-Pssession does not import cmdlets when used in a custom module - powershellCreating xml with DataSet tables - c #SQL Server Bidirectional Transactional Replication. Is this a good precedent? - sql-serverBackbone.js - loading the initial route with the base router and hashchange false - javascriptInstalling the Sencha SDK and creating the GS application - sencha-touchodbc_exec vs odbc_excute - phpIF NOT EXISTING IN PLSQL function - oracleReplace letters with encrypted texts - rAll Articles