Coder Social home page Coder Social logo

Comments (38)

jiangtianyou avatar jiangtianyou commented on May 16, 2024 4

reverse() 会改变数组本身,并返回原数组的引用。不是返回原数组吧,返回的是颠倒后的数组

from blog.

jerrybendy avatar jerrybendy commented on May 16, 2024 3

@honwenle '0' == false 确实是成立的,因为在比较的过程中会把两者都转换为整数 0,所以对比就变成了 0 == 0 ,自然是成立的。

第二个问题可以直接参考这篇文章:https://www.h5jun.com/post/why-false-why-true.html

from blog.

xiguaaxigua avatar xiguaaxigua commented on May 16, 2024 3

console.log(undefined === undefined); // true

from blog.

jerrybendy avatar jerrybendy commented on May 16, 2024 2

关于第 5 题严格模式下的好处我看到过另外一个版本大致是说:使用严格模式会增加代码检查的步骤并降低代码的执行效率,通常情况下在开发时使用严格模式,而在发布到生产环境时去掉严格模式的定义。与文中所述的“提高编译器效率,增加运行速度”完全相反。不知道哪个版本才是正确可行的,望指教,谢谢。

from blog.

bdbai avatar bdbai commented on May 16, 2024 2

还漏掉了一些 ES6 特性,比如 12 题可以用剩余参数实现,避免访问性能不佳的 arguments。

from blog.

adntin avatar adntin commented on May 16, 2024 2

@honwenle [] == ![] 解析器是这样解析的:左边 --> [].valueOf() 返回对象, 继续调用toString() --> "", 右边 --> false --> 0, 最终变成 "" == 0 , 所以返回true

from blog.

mqliutie avatar mqliutie commented on May 16, 2024 1

只有我觉得这些东西出在面试题中没什么必要么....

from blog.

Tongym162 avatar Tongym162 commented on May 16, 2024 1

第二条中 console,log(typeof a); //undefined,但是应该为number吧? 运行出来的结果也是这样
(function(){
var a = b = 3;
})();
console.log(typeof a)
console.log("a defined? " + (typeof a !== 'undefined')); // true
console.log("b defined? " + (typeof b !== 'undefined')); // true
VM232:4 number
VM232:5 a defined? true
VM232:6 b defined? true

from blog.

guonanci avatar guonanci commented on May 16, 2024 1

第3题语法错误看不下去:::

    (function() {
        console.log("inner func:  this.foo = " + this.foo);
        console.log("inner func:  self.foo = " + self.foo);
    }());

改成

    (function() {
        console.log("inner func:  this.foo = " + this.foo);
        console.log("inner func:  self.foo = " + self.foo);
    })();

from blog.

ThanksSirAlex avatar ThanksSirAlex commented on May 16, 2024 1

reverse() 会改变数组本身,并返回原数组的引用。不是返回原数组吧,返回的是颠倒后的数组

确实是返回原数组,因为会改变数组本身,所以原数组已经已经颠倒了。

from blog.

zhuzhuaicoding avatar zhuzhuaicoding commented on May 16, 2024

mark

from blog.

jasonleft avatar jasonleft commented on May 16, 2024

赞!

from blog.

beyond5959 avatar beyond5959 commented on May 16, 2024

第一条,用 obj.constructor 和 arr.constructor 也可以区分,不过 null 不行。

from blog.

honwenle avatar honwenle commented on May 16, 2024

第19条,'0'不是false。另外,如果能顺便解释一下[]==![]就更好了

from blog.

honwenle avatar honwenle commented on May 16, 2024

@jerrybendy 谢谢耐心解答,对于==我看过很多资料,还是不能完全理解,不过尽量都用===就好了

from blog.

findsomeoneyys avatar findsomeoneyys commented on May 16, 2024

谢谢~作为初学者学到了很多!

from blog.

Mageenz avatar Mageenz commented on May 16, 2024

这些题目在笔试的时候应该会出现

from blog.

YiBanCangBai avatar YiBanCangBai commented on May 16, 2024

老铁说的有道理👏

from blog.

lazyhero avatar lazyhero commented on May 16, 2024

赞 虽然工作中 一查就到 但是…… 面试考需要瞬间答上来 所以……还是看吧 明白其中原理的同学也不能松懈 毕竟 过一阵子不看又忘了-_-#

from blog.

zizizheng avatar zizizheng commented on May 16, 2024

第七題
console.log(undefined === undefined); //false
結果應該為 true?

from blog.

Joker0824 avatar Joker0824 commented on May 16, 2024

console.log(undefined===undefined)//这里应该是true

from blog.

xiangwenhu avatar xiangwenhu commented on May 16, 2024

var myObject = {
foo: "bar",
func: function() {
var self = this;
console.log("outer func: this.foo = " + this.foo);
console.log("outer func: self.foo = " + self.foo);
(function() {
console.log("inner func: this.foo = " + this.foo);
console.log("inner func: self.foo = " + self.foo);
}());
}
};
myObject.func();

所以第三个输出会报错,因为 this 在可访问到的作用域内是 undefined
不是undefined吧,浏览器中是window, nodejs中等于global

from blog.

plh97 avatar plh97 commented on May 16, 2024

绕晕了。。。我还是继续看js的调用栈补补基础

from blog.

rachelyao avatar rachelyao commented on May 16, 2024

console.log(undefined === undefined); //true

from blog.

tianmingzuo avatar tianmingzuo commented on May 16, 2024

问题14的关键点是push()方法, 与reverse()方法的关系不大:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi", "Lemon", "Pineapple"); //后插入单个元素:fruits.length=7, 即4+3
fruits.push(["Kiwi", "Lemon", "Pineapple"]); //后插入一个整体数组:fruits.length=5, 即 4+1

from blog.

tianmingzuo avatar tianmingzuo commented on May 16, 2024

问题14:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
若后插入一个整体数组:
fruits.push(["Kiwi", "Lemon", "Pineapple"]);
然后用slice(-1)方法, 则后插入的数组整体被弹出:
fruits.slice(-1);//Kiwi,Lemon,Pineapple

from blog.

tianmingzuo avatar tianmingzuo commented on May 16, 2024

第19题: 在非if语句中, 0, '0', +0, -0, false, '', null, undefined, null, NaN都被视为false。然而, 在if分支语句判断时, '0', [0], []被视为true,因为他们并非空元素(not null)。
另外, 在if分支语句判断时,{}也被视为true。

from blog.

tianmingzuo avatar tianmingzuo commented on May 16, 2024

在if分支语句判断时,只有0, false, '', null, undefined, NaN等6个值被视为false。

from blog.

juzhiyuan avatar juzhiyuan commented on May 16, 2024

请问 @dwqs 第14条,为什么arr1arr2.push(arr3) 之前便输出下图结果呢?

image

from blog.

tianmingzuo avatar tianmingzuo commented on May 16, 2024

@juzhiyuan: 你的问题是“JavaScript 是单线程, 为什么前面的语句会显示出程序完全执行后的结果?”。
要回答您的问题, 首先要明白:1. 数组是地址引用传递;2. console.log显示结果时程序已执行完毕,并非是程序正在执行时的结果。要想看到程序正在执行时每一步的结果,把其中的console.log换成alert语句,您就会看到所期待的结果。

from blog.

tianmingzuo avatar tianmingzuo commented on May 16, 2024

@juzhiyuan:
var arr1 = "john".split(''); //j o h n
alert(arr1); //j o h n
var arr2 = arr1.reverse(); //reverse() 会改变数组本身,并返回原数组的引用。
alert(arr1); //n h o j
alert(arr2); //n h o j
alert(arr1===arr2); //true; arr2是对原数组arr1的引用,即arr2指向了arr1的地址。
var arr3 = "jones".split('');
alert(arr3); //j o n e s
var arr4=arr2.push(arr3);
alert(arr1); //n,h,o,j,j,o,n,e,s
alert(arr1.length); //5; arr3 as the last object(not separated) in arr1, so arr1.slice(-1) gives out the last
object(arr3). so length=4+1=5;
alert(arr2); //n,h,o,j,j,o,n,e,s
alert(arr1===arr2); //true, arr2指向了arr1的地址,改变arr2也就是改变了arr1。
alert(arr4); //5; The push() method returns the new array length; arr4=arr2.push(arr3);
console.log("array 1: length=" + arr1.length + " last=" + arr1.slice(-1)); //array 1: length=5 last=j,o,n,e,s
console.log("array 2: length=" + arr2.length + " last=" + arr2.slice(-1)); //array 2: length=5 last=j,o,n,e,s

from blog.

juzhiyuan avatar juzhiyuan commented on May 16, 2024

@tianmingzuo 非常感谢!

from blog.

tianmingzuo avatar tianmingzuo commented on May 16, 2024

from blog.

guonanci avatar guonanci commented on May 16, 2024

@tianmingzuo 嗯嗯,

from blog.

jweboy avatar jweboy commented on May 16, 2024

求截图的 JS 语法规范的网站地址。

from blog.

mqliutie avatar mqliutie commented on May 16, 2024

@jweboy https://www.ecma-international.org/ecma-262/5.1/#sec-11.9.3

from blog.

llxiaozz avatar llxiaozz commented on May 16, 2024

第3题语法错误看不下去:::

    (function() {
        console.log("inner func:  this.foo = " + this.foo);
        console.log("inner func:  self.foo = " + self.foo);
    }());

改成

    (function() {
        console.log("inner func:  this.foo = " + this.foo);
        console.log("inner func:  self.foo = " + self.foo);
    })();

都可以的喔,前面用+号都行。

from blog.

KamingInWork avatar KamingInWork commented on May 16, 2024

你的第十三题在我看来是错误的
输出console 都是5不是因为IIFE的问题,而是在构建JS执行上下文的函数环境的时候就给i声明了他作用域,这个时候
你将for (var i = 0; ...; i ++) 改成for (let i = 0; ...; i ++) , 直接输出正确的结果
另外,如果真的是IIFE的问题,请给个答案,我不太懂,求指教

from blog.

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.