0

I got this open source JS project and trying to browse the code I found this several times:

if(evt.success){
    ;
    evt.success(response.result);
}

An empty line ending with a ";"

Does this mean something ? or it's just a typing error ?

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Alucard
  • 1,814
  • 1
  • 21
  • 33

3 Answers3

3

It is perfectly valid. It will just be treated as an empty line/statement and nothing will happen. But it does not mean anything special that you need to worry about if you were to remove it.

As to why it's in your code I don't know. If it was just a single instance I would go with a typo, but multiple instances I would say either on purpose, or a result of some code generation perhaps (and it could be a typo in that), or some other reason - we cannot know without finding the person who made the decision to include it.

musefan
  • 47,875
  • 21
  • 135
  • 185
1

valid statement that does nothing, so you can delete it, so you don't have to look at it, without worry

workabyte
  • 3,496
  • 2
  • 27
  • 35
0

This is one of the approach to defensive programming in javascript. Consider something like this:

var y=x+f
(a+b).toString()

This will be interpreted as:

var y=x+f(a+b).toString()

Using ; before the beginning of statement eliminated problems like above.

Jack_of_All_Trades
  • 10,942
  • 18
  • 58
  • 88
  • 1
    yeah, but why at the start of an if block? when there is nothing before it? Oh and your so called `"true reason"` is speculative, you don't know why the developer did it – musefan May 20 '14 at 15:34
  • 1
    It might be something the programmer did out of habit but what I am trying to explain to OP was the reason behind it. Yes, it does not make sense in the code above however. – Jack_of_All_Trades May 20 '14 at 15:36
  • My point is you are explaining one possible reason, in your opinion, you cannot state it is the correct reason for sure. Your answer seems to be worded that you are 100% sure it is the correct reason – musefan May 20 '14 at 15:41
  • 1
    @musefan; We all have little biases, I guess when we try to answer anything. Your answer suggested, typo or some other reason. I gave one of the reason . Is it relevant to the code OP posted? Of course not, but logical explanation why it appeared there would be the one who did it had habit of starting something important with ;. – Jack_of_All_Trades May 20 '14 at 15:51
  • You are either not understanding me, or just avoiding my point completely. All I was saying is that you worded it as fact, when it was opinion. You have since edited you post, and now I think it is fine – musefan May 21 '14 at 08:49