Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Semicolon on jQuery

The following jQuery works with or without a semicolon after the function. Why?

jQuery(document).ready(function(){
jQuery("#red").treeview({
    animated: "fast",
    collapsed: true,
    control: "#treecontrol",
    persist: "cookie"
})

});

It works on all browsers. Wouldn't this cause an error?

like image 803
AlxVallejo Avatar asked May 15 '12 15:05

AlxVallejo


People also ask

Do you need semicolons in jquery?

For the most part, yes, it does require a semi-colon after each statement but there are times when doing so could stop the rest of your code from being read.

Do you use semicolons in JavaScript?

Semicolons are an essential part of JavaScript code. They are read and used by the compiler to distinguish between separate statements so that statements do not leak into other parts of the code. The good news is that JavaScript includes an automatic semicolon feature.


1 Answers

JavaScript doesn't actually require semicolons. That's just convention.

http://inimino.org/~inimino/blog/javascript_semicolons

I recommend using semicolons, just like I'd recommend indenting your code.

like image 156
Brad Avatar answered Sep 19 '22 18:09

Brad