Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
pakoch

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...