-2

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
  • 39
  • 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
  • 22,120
  • 7
  • 61
  • 65
0

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

Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
Tim B
  • 40,716
  • 16
  • 83
  • 128
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
  • 12,193
  • 3
  • 33
  • 46