JS Startup

Challenges, Tips & Tricks & Tutorials

JavaScript Quiz – effect of misplaced semicolon after if statement

JavaScript Quiz – effect of misplaced semicolon after if statement

Misplaced semicolon

In javascript, misplace semicolon plays an important role in creating human error which sometimes becomes functionality. But sometimes it leads to error. That can only be identified by humans.

A semicolon use as a statement terminator. But in a new update, it’s not mandatory to use a semicolon.

Syntax of SemiColon


JavaScript Question

In this javascript quiz, find out effect of misplaced semicolon after if statement as semicolon is used to terminate code statement.

First, we declare a variable num and assign number to it whose value is 10.

let num = 10;

In the second step, create a if statement in which we match a num value with 11 if it’s true then assign value of 5 to it.

if(num == 11);
 num = 10;

Now, we check the value of num variable using console log.


Any idea what should be the output of above code statement.

JavaScript Quiz Test

Here is the full javascript code snippet for you to solve.

let num = 10;

if(num == 11);
  num = 5

console.log(num); // output => 🧐 ?

// Made with ❤️, by @jsstartup

Answer – 5

Click To Run Code


Now, you know the answer is 5. But why, doesn’t it value should be 10. Let me explain.

InShort, it happen due to misplace semicolon. If you see that after the if statement semicolon is used which terminate the if condition.

After that a curly braces is used which create a block scope. That block always run even condition is true or false.

At last, That’s why we get an answer “5“.

Let me know in the comment section, what you think about it.

I hope you understand the concept and logic behind it.

But wait, i have something more for you –

Check out our other javascript quiz – 

  1. JS Quiz – does get date and month from date object is same
  2. JS Quiz – does the string startsWith() method return true
  3. JavaScript Quiz – boolean return value true with string or not
  4. JavaScript Quiz – can mixed case array sort is possible


To participate in our javascript quiz or challenges, tutorial, tips & tricks make sure to join our jsstartup newsletter. So, you can able to participate in our daily challenges & learn the javascript concept.

And last but not the least, don’t forget to like, comment and share. It gives us a morale boost to remain to continue. Also, join our Facebook Page

If you have any questions, please feel free to ask me in the comment section and also let me know if you have any suggestions. As suggestions are always welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top
Share via
Copy link