Jump to content
Larry Ullman's Book Forums

Missing Brackets In A Function


Recommended Posts

Hi,

 

Here is an observation and a question.  I noticed that when a mating curly bracket is left out of the code, like in an "if" statement, nothing on the entire .js page is executed.  

 

if (something !== undefined)  {

  

   do something

 

}  else {

 

  do something else

}

 

Since the curly bracket that I neglected to type was in the middle of the page, I would assume that at least some of the code before that part of the function would get executed, but that does not seem to be the case. 

 

Is this normal behaviour for JavaScript?  If so, then the entire page must be analyzed before any of it is acted on.

 

Thanks,

Peter Koch

Link to comment
Share on other sites

It's completely context dependent.

For example, if you forget to use an opening curly bracket for an if statement within a function, then you will likely end up ending the function early, which will then likely cause a stray ending curly bracket to be in the global namespace, which would definitely cause no JS to be executed.

There are also any number of factors to consider depending on the browser, as every browser (and even different versions of the same browser) have different ways of parsing/interpreting JS.

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...