Javascript conditionals: Difference between revisions
From wikinotes
No edit summary |
(→If Not) |
||
Line 1: | Line 1: | ||
= If Not = | = If Not = | ||
<blockquote> | <blockquote> | ||
Not requires an additional set of brackets. | |||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
if !(foo == "bar") { ... } | if (!(foo == "bar")) { ... } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- If Not --> | </blockquote><!-- If Not --> |
Revision as of 22:58, 14 September 2021
If Not
Not requires an additional set of brackets.
if (!(foo == "bar")) { ... }
If Statements
if (var == "one") { // ... } else if (var == "two") { // ... } else { // ... }
case/switch statements
switch (var) { case 'one': // ... break; case 'two': // ... break; default: // ... }
Ternary Condition
If id is 1, name is 'will', otherwise is 'guest'
let name = (id == 1) ? 'will' : 'guest'