From the course: JavaScript: Best Practices for Data
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Add parentheses to clarify logic - JavaScript Tutorial
From the course: JavaScript: Best Practices for Data
Add parentheses to clarify logic
- [Instructor] The start code for this video generates three choices randomly from an array, then it has the logic to ensure all three are different. Line 21 is pretty straightforward, but in line 24, I'm checking to make sure the third choice variable is different from first choice and from second choice. If my screen was a little smaller, that statement would even run over a couple lines, and it uses a total of three operators. That can make it hard to read, and every time I come to this line while debugging, I have to stop for a minute to remember just what it's doing. Both mathematical and logical operations in JavaScript have a specific order that the parser follows. For instance, this is the order of operations for a few common logical operators. As long as I'm writing code with this order in mind, it'll work correctly. But there's a difference between a parser understanding the code and me or another developer…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Use triple-character equality operators2m 56s
-
(Locked)
Don't use Yoda conditions1m 52s
-
(Locked)
Compare appropriately for the data type2m 2s
-
(Locked)
Use ternary statements judiciously3m 23s
-
(Locked)
Add parentheses to clarify logic2m 3s
-
(Locked)
Challenge: Compare values53s
-
(Locked)
Solution: Compare values9m 29s
-
(Locked)
-