Giter Site home page Giter Site logo

Comments (25)

huguangju avatar huguangju commented on June 18, 2024 12

@Stevenzwzhai 这样可能要好理解些:

  • 1 + - + + + - + 1
  • 1 + (- + + + - + 1) // (- + + + - + 1) 这步主要就是用一元负号(-)运算符和一元正号(+)运算符,反复作用于操作数。从右往左依次消除符号:
    • - + + + (- 1)
    • - (+ + + (- 1)) // 一元正号的作用:计算其操作数的数值,如果操作数不是一个数值,会尝试将其转换成一个数值。这里的操作数是-1,所以可以消掉全部正号
    • - (-1)
    • 1
  • 1 + 1
  • 所以结果为2

这道题考察的是对一元正负号的理解吧(不要误把+ +当成递增运算符

from blog.

jelly7723 avatar jelly7723 commented on June 18, 2024 3

对于第6题的解释,楼主可能说错了。
js中可以表示的最大整数不是2的53次方,而是1.7976931348623157e+308。
2的53次方不是js能表示的最大整数而应该是能正确计算且不失精度的最大整数,可以参见js权威指南。
9007199254740992 +1还是 9007199254740992 ,这就是因为精度问题,如果 9007199254740992 +11或者 9007199254740992 +111的话,值是会发生改变的,只是这时候计算的结果不是正确的值,就是因为精度丢失的问题。

from blog.

loudou140806 avatar loudou140806 commented on June 18, 2024 2

第一题不用猜测,传0就是按照10进制http://www.w3school.com.cn/jsref/jsref_parseInt.asp

from blog.

FeMiner avatar FeMiner commented on June 18, 2024 2

第21题,请您自己运行一下看看结果

from blog.

liuxiaojiu avatar liuxiaojiu commented on June 18, 2024 1

@xiaoyu2er 你好,我看错了。不好意思

from blog.

paranoidjk avatar paranoidjk commented on June 18, 2024 1

@xiaoyu2er
在没有指定基数,或者基数为 0 的情况下,JavaScript 作如下处理:

  • 如果字符串 string 以"0x"或者"0X"开头, 则基数是16 (16进制).
  • 如果字符串 string 以"0"开头, 基数是8(八进制)或者10(十进制),那么具体是哪个基数由实现环境决- 定。ECMAScript 5 规定使用10,但是并不是所有的浏览器都遵循这个规定。因此,永远都要明确给出radix参数的值。
  • 如果字符串 string 以其它任何值开头,则基数是10 (十进制)。

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/parseInt

from blog.

renaesop avatar renaesop commented on June 18, 2024 1

刚刚仔细思考了一下13题,我认为这是原型继承的本质。

prototype的语义是原型,new的语义,是对原型的克隆。new 出来的东西(比如说array),最自然情况的是和原型相同,所以反推就有: Array.prototype是一个数组, String.prototype是一个字符串,Function.prototype是一个函数。正式这种貌似“奇怪”的行为,才真正遵循了原型的语义。

另外一个例子是,instanceof判断的依据是实例的方法是不是具有prototype的方法。这个相当于是new的逆过程。

准备再探索一下起源,感觉网上说原型本质的好稀有。

from blog.

renaesop avatar renaesop commented on June 18, 2024 1

renaesop/blog#17

from blog.

10081677wc avatar 10081677wc commented on June 18, 2024 1

MIN_VALUE 属性是 JavaScript 中可表示的最小的数(接近 0 ,但不是负数),它的近似值为 5 x 10-324。

from blog.

jparser avatar jparser commented on June 18, 2024 1

第20题

这个题跟 6 题差不多,都是精度问题
111111111111111110000..toString(2) =>
1100000010111111001111101101101110100011000101111001000000000000000 总共为 67 bits,
前 53 bits 为 11000000101111110011111011011011101000110001011110010
剩下 14 bits 00000000000000,这14 位的值用来计算舍入的,当值小于 8192 (即 0b10000000000000,或 1<< 13)舍掉,大于 8192 时进入。当等于 8192 时,由于53 bits的最后一位是 0,所以也舍掉;如果53 bits的最后一位是 1 的时候,就会进入 。
回到原题,

var a = 111111111111111110000, 
    b = 1111; 
a + b;

当 b <= 8192 时, a + b = a。

from blog.

lovecn avatar lovecn commented on June 18, 2024

看来我基础还是不行呀

from blog.

liuxiaojiu avatar liuxiaojiu commented on June 18, 2024

19题,答案应该是21吧。

from blog.

xiaoyu2er avatar xiaoyu2er commented on June 18, 2024

@liuxiaojiu 你说的是第一种情况还是第二种, 第一种情况就是 21. 如果参数列表出现了 reset, default param 这种语法的话 就不是了.

from blog.

NoManReady avatar NoManReady commented on June 18, 2024

keng

from blog.

Thinking80s avatar Thinking80s commented on June 18, 2024

基础很重要啊!

from blog.

xiaoyu2er avatar xiaoyu2er commented on June 18, 2024

@jelly7723 谢谢指出, 我把你的理解修改到文章中

from blog.

xiaoyu2er avatar xiaoyu2er commented on June 18, 2024

@paranoidjk 谢谢指出 已添加到正文

from blog.

xiaoyu2er avatar xiaoyu2er commented on June 18, 2024

@stellar91 这个笔者实践了一下 发现 firefox 是 window, chrome 报错 VM190:2 Uncaught TypeError: Array.prototype.reverse called on null or undefined(…) 可能是实现不同, 在 chrome 中应该是对调用者做了检查.

from blog.

Stevenzwzhai avatar Stevenzwzhai commented on June 18, 2024

17题不是很理解,求详解

from blog.

wolfjyx avatar wolfjyx commented on June 18, 2024

第20题 ,因为Math(2,53)<111111111111111110000, 计算失去精度

from blog.

houyhea avatar houyhea commented on June 18, 2024

有没有办法让1+1==3?

from blog.

llli0v0 avatar llli0v0 commented on June 18, 2024

谢谢分享

from blog.

seekersIsMe avatar seekersIsMe commented on June 18, 2024

谢谢分享

from blog.

changhongWang avatar changhongWang commented on June 18, 2024

第19题还是有点没看明白呢。。

from blog.

Borkes avatar Borkes commented on June 18, 2024

学习一下

from blog.

Related Issues (16)

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.