-1

I wonder the difference between two codes below in JavaScript, welcome answer.

Code 1:

function Add(a,b) {
    return a + b;
}

Code 2:

function Add(a,b) {
    return a + b;
};
liukuo362573
  • 41
  • 10

3 Answers3

1

The second code contains an empty statement. You can add as many as you want.

function Add(a,b) {
    ;;;;;
    return a + b;;;;;;;
};;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Prinzhorn
  • 21,577
  • 6
  • 58
  • 64
0

There is no difference. The ; in the second example just creates an empty statement there.

Hanky Panky
  • 45,969
  • 8
  • 69
  • 95
Tim B
  • 39,784
  • 16
  • 75
  • 127
0

First one is the standard method

Second one is not recommended.. Use the first method

Further reading - Why should I use a semicolon after every function in javascript?

Community
  • 1
  • 1
Kavindu Dodanduwa
  • 10,909
  • 3
  • 31
  • 44