作者s25g5d4 (function{}())
看板Web_Design
标题Re: [讨论] 面试时碰到的一些 Javascript考题
时间Wed Jun 12 20:42:05 2013
※ 引述《WJames (星晨)》之铭言:
: 这不是作业,也不是 take home exam。
: 这是小弟在应徵工作时碰到的 JS考题。
: 免试早已经结束,只是当时有用手机将考题拍下来。
: 想说有机会可以上来跟强者讨论讨论,很想知道正确解答,
: 跟我的作答差距多少,由於公司也没告诉我正确答案(笔试),试卷他们收走
: 我也不好意思问,就post在版上,让各位前辈强者有兴趣的话回答一下罗。
: 也算是分享应徵考试的经验给大家。
: 1. which is equl to the condition
: if( ua !== 'IE 6'&& ua != 'IE 7')
: A) if( ua === 'IE 6' || ua === 'IE 7')
: B) if( ua === 'IE 6' && ua === 'IE 7')
: C) if( !( ua === 'IE 6'|| ua === 'IE 7') )
: D) if( !( ua === 'IE 6'&& ua === 'IE 7') )
C
这题要先从 statement 的反面下手
不等於 改成 等於
且 改成 或
用中文解释的话就是 ua不是IE6且ua不是IE7 的反面是 ua是IE6或ua是IE7
最後再否定他 就是否定的否定=肯定
这个好像叫做 迪摩根定理
: 2. Which is false ?
: A) 1 == '1'
: B) NaN == NaN
: C) 1 == [1]+[]
: D) undefind === undefined
B
老梗题目了...
不过这题的 C 我还是搞不懂怎麽解释他
: 3. Which is true ?
: A) 1=== true
: B) Number('1px')
: C) typrof [1,2,3] == 'array'
: D) '0'
D
在判断真假的时候 字串会被转为ascii字码
'0'会被转换成30 大於0所以为真
: 4. What is b :
: var a = [ 1, 2, 3 ];
: var b = a;
: a.push(5);
: console.log(b)
[1,2,3,5]
object 与 array 都是传址
array 可以呼叫 .slice(0) 进行复制
object 要透过回圈
: 5. Please answer below two "this"?
: $('#foo').on('click', function(e){
: console.log( this ); //What is this ?
native DOM node #foo
: setTimeout( function(){
: console.log( this ); //What is this ?
全域物件window
: }, 1000}
: })
这题要讲解有点困难... 可以跳过吗QQ?
http://rettamkrad.blogspot.tw/2012/11/how-this-works-in-javascript.html
: 6. How can get the 'hello':
: var obj = { 1: 'hello', 2: 'world'}
: A) obj.1
: B) obj[0]
: C) obj[1]
: D) obj.2
C
这题应该不用说明吧
A 与 D 会发生例外 syntax error: unexpected number
: 7.Please answer all below typeof:
: typeof function(){}
'function'
: typeof new Date()
'object'
: typeof {}
'object'
: typeof new Array()
'object'
我的记法是除了基本资料型态以外都是回传 'object'
function 会回传 'function'
还有个例外是 undefined 会回传 'undefined'
但是 null 会回传 'object' 是个很大的陷阱 不亚於 array 回传 'object'
: 8.What do you think foo() is ?
: if(1) function foo(){ return 'a'}
: else function foo(){ return 'b'}
: console.log( foo() )
'b'
function declaration vs expression
http://tinyurl.com/34b4udr
http://tinyurl.com/kzs7yd9
: 9.What is the console.log output?
: function foo(){
: return this;
: }
: console.log( foo.call( foo ) )
function foo() { 略 }
http://dreamerslab.com/blog/tw/javascript-call-and-apply/
: 10.Please explain what is the difference between "setTimeout()" and
: "setInterval()" ?
一个是只执行一次 另一个是重复执行
: 11.Please explain what the use of "preventDefault()" and ""stopPropagation()"
: in Event Object ?
preventDefault 是取消 event 的预设行为
像是对 <a> click 会造成换页、<input type="submit">会送出表单之类
stopPropagation()是阻止事件向更上层的元素传播
像是巢状的 div 标签
<div id="first">
<div id="second">
<div id="third">Click me!</div>
</div>
</div>
对 div#third, #second, #first 监听 click 事件
并在 #second 的 handler 使用 event.stopPropagation() 的话
就不会触发 #first 的 click 事件
http://jsfiddle.net/KwtP7/
: 以上 就这几题
: 至於是哪家公司的面试题目 我就不透漏了,透露出来好像不太好
--
1F:推 jumbotest:反正操你妹应该只是基本作 她开心就好 01/21 15:40
2F:→ jumbotest: 操01/21 15:40
3F:→ jumbotest:我没有骂脏话01/21 15:44
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.127.251.59
4F:推 WJames:感谢推...但是蛮想听听第五题的讲解的...QQ 06/13 01:48
5F:→ WJames:或是有推荐什麽参考资料吗? 我自己看 06/13 01:49
补上参考连结:
http://rettamkrad.blogspot.tw/2012/11/how-this-works-in-javascript.html
※ 编辑: s25g5d4 来自: 59.127.251.59 (06/13 02:25)
※ 编辑: s25g5d4 来自: 59.127.251.59 (06/13 02:47)
6F:推 rettamkrad:object(array)遇到+号都是先转成字串,所以变成'1'+'' 06/13 18:58
7F:推 applexva:推 06/15 10:11