• Post author:
  • Post category:Blog
  • Reading time:2 mins read
  • Post last modified:June 12, 2024

Review the following code:

if (counter <= 10) {
    if (counter >= 10) {
     console.log(1);
    }
}

We can replace it using:

  • if (true) console.log(1); 
  • if (false) console.log(1); 
  • if (counter >= 10) console.log(1); 
  • if (counter == 10) console.log(1);
Explanation & Hint:

The given code snippet can be simplified by removing the nested if statement, as it does not have any effect on the logic. In the simplified code, we directly check if the counter variable is equal to 10 using a single if statement. If the condition is met, meaning counter is exactly 10, then 1 will be logged to the console.

For more Questions and Answers:

JavaScipt Essentials 1 (JSE) | JSE1 – Module 4 Test Exam Answers Full 100%

Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments