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?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With