From the course: Learn JavaScript: Write Modern Code with JavaScript ESNext
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Learn about if-statements in JavaScript - JavaScript Tutorial
From the course: Learn JavaScript: Write Modern Code with JavaScript ESNext
Learn about if-statements in JavaScript
- So now that we've gotten the subject of equality out of the way, let's take a look at one of the most common places where equality is used, and that's if statements. The basic syntax of if statements in JavaScript is, well, pretty boring. It's really similar to most other languages. The only thing that might be a little different is that in JavaScript, that condition has to be surrounded by parentheses. In other words, we can't leave the parentheses off like we can in languages such as Python. And of course we can add else if and else blocks to our if statement. Just like in other languages, the else if block will only be executed if none of the conditions in the blocks before it are truthy and its own condition is truthy, whereas the else block will only be executed if none of the other conditions in the other blocks are truthy. Okay, so you may be wondering why I am using the words truthy and falsey instead of just true and false. Maybe you remember that earlier in the course when…
Contents
-
-
-
-
-
(Locked)
Learning objectives1m 16s
-
Learn about equality in JavaScript5m 31s
-
(Locked)
Learn about if-statements in JavaScript4m 8s
-
(Locked)
Learn about for-loops in JavaScript4m 53s
-
(Locked)
Learn about while-loops and do-while loops in JavaScript1m 29s
-
(Locked)
Handle and throw errors in JavaScript2m 34s
-
(Locked)
Learn about switch-case blocks in JavaScript1m 53s
-
(Locked)
Learn about ternary operators in JavaScript1m 34s
-
(Locked)
Learn the difference between block-scoped and function-scoped variables4m 29s
-
(Locked)
-
-
-
-
-
-
-
-
-