I accidentally wrote a wrong JavaScript syntax (I think so).
code is
var temp = {};
temp.a = 34;
height:34, //should fail here.
temp.b = 56;
jsfiddle
is syntax is correct?
Thanks.
Syntax errors in Javascript cannot be handled by using try-catch blocks as they are thrown while the code is being parsed. The window. onerror() function can be used instead to figure out that there is a syntax error.
SyntaxError is a perfectly ordinary built-in exception. It is not special in any way. Only the circumstances of when it's (usually) thrown are a bit unusual. A syntax error means that the code featuring said error cannot be parsed.
In computer science, a syntax error is an error in the syntax of a sequence of characters or tokens that is intended to be written in a particular programming language. For compiled languages, syntax errors are detected at compile-time. A program will not compile until all syntax errors are corrected.
A SyntaxError is thrown when the JavaScript engine encounters tokens or token order that does not conform to the syntax of the language when parsing code.
A colon can be used to label a statement, and that's what's happening here. There are no errors in your code, it's intended behavior.
Edit: better resource on labels. :)
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