Giter VIP home page Giter VIP logo

Comments (3)

Jemair avatar Jemair commented on July 21, 2024 1

2..valueOf() == 2.0
输出22
如果这里是**2.valueOf()**就会报错
程序从左向右读,会把数字后面的第一个.识别为小数点,第二个点才会识别为操作符

from frontend-interview.

hungeroxc avatar hungeroxc commented on July 21, 2024

输出结果22:


原因:
1.2..valueOf()中用到两个点是因为JS对数字后面的第一个点识别为小数点,第二个点识别为运算符,
2..valueOf()得出的结果是数字2;

2.({z : 10, x : 20}).x)中相当于求对象{z : 10, x : 20}中x的值,x值为20,所以({z : 10, x : 20}).x)结果是20;

3.得出(2..valueOf() + ({z : 10, x : 20}).x)等于2+20为22;

from frontend-interview.

kangning1206 avatar kangning1206 commented on July 21, 2024

比如:2.4.valueOf() 结果是2.4,因此及第一个点号是数字的,第二个点号 是点号运算符。

from frontend-interview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.