Parse JavaScript midpoint number "." The ambiguity

Source: Internet
Author: User

This article mainly describes the JavaScript midpoint "." The ambiguity. Need friends can come to the reference, I hope to help you

Point number "."     There are two semantic semantics in JavaScript 1, the decimal point in arithmetic (floating-point number), such as 2.5 semantics 2, object properties, methods, such as [].push (2) There is hardly any hard to understand, but the following question is interesting.    The code is as follows://How this line of code executes 1.toString ();   The dot number in the Firebug is expressed in the above semantic 1, so the dot must be followed by a number, here with ToString, the report syntax is wrong.    The workaround is simple, such as adding a parenthesis code as follows: (1). ToString ();   It can be written in this way, but it's hard to understand some code as follows: 1..toString (); The reason why the browser can run, because the browser JS engine to "1..toString ()" understood as "1.0.toString ()".   The first point here is semantic 1, and the second point is the semantics 2. There's even more strange writing, and there's no error. Copy code code as follows: 1. toString (); Note that the dot is preceded by a space. Obviously, the point number here is Semantic 2, that is, the JS engine ignores the space in front of the dot operator, regardless of the space before or after it is ignored. The following code is as follows: 1. ToString ();  There is a space of 1 before and after the dot number. ToString (); There are two spaces around the point number 1. toString ();    There is a tab 1 before the dot number. ToString (); The dot before and after each have a tab JS engine will not only ignore spaces, but also ignore the tab.
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.