看板 Web_Design 關於我們 聯絡資訊
※ 引述《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/ : 以上 就這幾題 : 至於是哪家公司的面試題目 我就不透漏了,透露出來好像不太好 --
jumbotest:反正操妳妹應該只是基本作 她開心就好 01/21 15:40
jumbotest: 操01/21 15:40
jumbotest:我沒有罵髒話01/21 15:44
-- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.127.251.59
WJames:感謝推...但是蠻想聽聽第五題的講解的...QQ 06/13 01:48
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)
rettamkrad:object(array)遇到+號都是先轉成字串,所以變成'1'+'' 06/13 18:58
applexva:推 06/15 10:11