1

There being a ' ; ' after one and not the other. I was wondering if there was a difference or additional functionality between these 2 if statements?

func(x){  // with a ; at end
    if (false){
        throw new Error('blah');
    };
}

func(x){  // without a ; at end
    if (false){
        throw new Error('blah');
    }
}
3
  • 1
    A semi-colon ends a statement. A statement can be empty. So you can even do };;;;;;;;;;;; and it will still be OK. Commented May 11, 2020 at 21:02
  • What is funt - intentional typo ??? Commented May 11, 2020 at 21:05
  • haha was a typo, thank you guys. Commented May 11, 2020 at 21:25

2 Answers 2

2

There's no difference.

You don't need a ; after a statement block. If you add one, it's just terminating an empty statement, which doesn't do anything.

The first version is probably a typo, it's not normal to put a ; there.

Sign up to request clarification or add additional context in comments.

Comments

0

There is no differences or additional functionality between the 2 statements

Semicolons are optional in javascript, the interpreter will insert a semicolon at the end of a statement if needed.

In other programming languages like C, the semicolon denotes to the compiler the end of one instruction and the beginning of the next.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.