The strange If-else if-else in JavaScript

Source: Internet
Author: User

Recently the head is a little dizzy, in JavaScript write If-else If-else code, actually to else added conditions. The code is as follows:

<script>var i=10;if (i<=10) {    alert (111);} Else (i>10) {    alert (222);} </script>

IE9 and Chrome under the execution of this script, found not to prompt the JS error, the program's execution result is: The first popup 111 dialog box, after the Popup 222 dialog box. That is to say, if and else these 2 branches will execute, this traditional C/java difference is very big. The project I wrote with this similar brain code, the results for a long time did not see the problem. JavaScript as an interpreted language, syntax requirements and compiler hints are not as strict as java/c. When writing JavaScript, be careful and prescriptive, or you may find yourself in a very strange situation.

Why do the above JavaScript code work? Not clear, welcome the Great god explanation, the guidance.

The strange If-else if-else in JavaScript

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.