JavaScript Programmer ? Do you also ignore semicolon?

A little story of two JS Programmers ==> Alice and Bob

Bob: Hey Alice. You know what, I have learned JavaScript very well. It’s very easy and fun.

Alice: Good, but you still need to be careful while writing you JS program.

Bob: Are you kidding me ? Careful with JavaScript? Several times I escape putting the semicolons at the end of the statement and you know it still works like charm.

Alice: You must be kidding. You shouldn’t forget to put the semicolon after the statement.

Bob: I am serious, who wants to put that reoccurring and irritating semicolon.

Alice: Of course JS ignores such things at several places, BUT  it doesn’t mean you should abuse this behavior.

Bob: Why not? I can do the following and it works perfectly fine:

    console.log("Hello! I missed the semicolon.")
    console.log("Hello! I missed the semicolon too.")
Output:
    Hello! I missed the semicolon.
    Hello! I missed the semicolon too.

What harm does it do?

Alice: Well, I think nothing till now. Bob can you do me a favor? Can you just put both the statements in the same line as it is?

Bob: Sure!

    console.log("Hello! I missed the semicolon.") console.log("Hello! I missed the semicolon too.")

Output:

    SyntaxError: Unexpected identifier

Bob: What!!!!!!!!!??????????
Bob: But wait, putting two statements in the same line is itself not good.
Alice: Fine(probably he doesn’t know about minification). Ok tell me the purpose of this code:

    +("233434");

Bob: Its just a way to convert the string to number.
Alice: Exactly. Now what do you expect from of the following code written in your style:

    var a = 0
    var b = 1
    +("23456")

Bob: Its too straight forward: 0 is assigned to variable “a” and the value 1 is assigned to the variable “b”.
Alice: Are you sure?
Bob: Wait ! Wait ! Wait ! Wait !. Oh I see the problem.
Bob: Hmmmm! You are right I shouldn’t miss my best friend semicolon.

Advertisements