I added HTML code because the syntax error does not occur on Internet Explorer 8 (for example) and it is easier to test when you have the entire code ready.
So you are basically saying that "if" and "else" do not count as two statements, right? I guess I am confused, because I recently found out you can actually run this code without any error - if (some_condition) some_function(); else some_other_function(); ☆*PhistucK* 2011/1/28 Mikael Helbo Kjær <[email protected]> > Hi there. > > > > This is not the usual thing to ask here (I’d go for some sort of Javascript > forum in the future). > > > > I think you don’t need to include any sort of HTML here to get ppl to look > at your JS. > > > > First problem: > > You have a ; after the end of your if block (I’ve marked it below), that > ends the if else statement too early. Else cannot stand alone so to speak. > > > > Second problem: your blocks are not entirely right here. The parser can > only follow the rules here. The if sentence either deals with the next > statement (line) or block. Only if that line or block is directly followed > by an else or else if can that be included. A corrected (untested assumption > here) example could be (there is more than one way to do it): > > > > var a = “0” > > var b = “c” > > if (a == “0”) > > { > > if (b == “b”) > > { > > alert(“a is o”); > > alert(“b is b”); > > } > > } > > else > > { > > alert(“a is not o”); > > } > > > > /Mikael > > > > When I try this code - > > <!DOCTYPE HTML> > > <html> > > <script> > > var a = "o"; > > var b = "c"; > > if (a == "o") > > if (b == "b") > > { > > alert("a is o"); > > alert("b is b"); > > }; ß Problem here > > else > > { > > alert("a is not o"); > > }; > > </script> > > </html> > > > > It shows - > > Uncaught SyntaxError: Unexpected token else > > > > Should that error be triggered? can you explain why? > > > > > > > > Also, running it without that semicolon - > > <!DOCTYPE HTML> > > <html> > > <script> > > var a = "o"; > > var b = "c"; > > if (a == "o") > > if (b == "b") > > { > > alert("a is o"); > > alert("b is b"); > > } > > else > > { > > alert("a is not o"); > > }; > > </script> > > </html> > > > > Shows an alert - "a is not o". > > As far as I know, "if" and "else" count as two statements. If they are, the > "else" block is actually part of the first "if" statement. > > Am I misinformed, or is it a bug? > > > > -- > v8-users mailing list > [email protected] > http://groups.google.com/group/v8-users > -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users
