Giter VIP home page Giter VIP logo

Comments (4)

Jemair avatar Jemair commented on August 23, 2024 1

补充上面
(!"world", !!"from here!!") == !!"from here!!"

from frontend-interview.

VamKram avatar VamKram commented on August 23, 2024

var x = !!"Hello" + (!"world", !!"from here!!"); -> var x = true + true -> var x = 1+1 -> x=2

from frontend-interview.

WangXiaoyugg avatar WangXiaoyugg commented on August 23, 2024

var x = !!"Hello" + (!"world", !!"from here!!");
等同于 var x= true+(false,true),
MDN 中逗号运算符,对它的每个操作对象求值(从左至右),然后返回最后一个操作对象的值。
因此等同于 var x= true+ true=2

from frontend-interview.

hungeroxc avatar hungeroxc commented on August 23, 2024

不会报错,输出为2;
原因:var x = !!"Hello" + (!"world", !!"from here!!");
因为这三个字符串都有取反运算符!,所以可以转化为布尔值,式子可以变形为
var x = true + ( false , true )
然后因为括号,所以先计算( false , true ),又因为里面有逗号运算符,所以输出true,式子变成了
var x = true + true
因为有+运算符,所以true被转化为数字1,所以最后结果x的值为2

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.