看板 Ajax 關於我們 聯絡資訊
※ 引述《WJames (星晨)》之銘言: : ※ [本文轉錄自 Web_Design 看板 #1Hk5i6oO ] : 作者: WJames (星晨) 看板: Web_Design : 標題: [討論] Javascript 一些問題 : 時間: Wed Jun 12 19:26:59 2013 : 這不是作業,也不是 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 是答案。簡單的集合測驗而已。 這題非常基本,沒拿到分數請自我檢討 : 2. Which is false ? : A) 1 == '1' : B) NaN == NaN : C) 1 == [1]+[] : D) undefind === undefined B,不過考這題沒啥營養,純粹就是考知不知道 NaN == NaN 這個特例。 : 3. Which is true ? : A) 1=== true : B) Number('1px') : C) typrof [1,2,3] == 'array' ^^^^^^ 應該是 typeof : D) '0' 這題 A 是 false B 是 NaN C 是 typeof [1,2,3] 是 object (in all browser and nodejs) D 是 string 嚴格來說是無解 : 4. What is b : : var a = [ 1, 2, 3 ]; : var b = a; : a.push(5); : console.log(b) [1,2,3,5] ,因為 call by pointer 這題非常基本,沒拿到分數請自我檢討 : 5. Please answer below two "this"? : $('#foo').on('click', function(e){ : console.log( this ); //What is this ? : setTimeout( function(){ : console.log( this ); //What is this ? : }, 1000} ^ typo : }) 假設是 jQuery 的前提下 第一個 this 是 #foo ,因為 jQuery 是這樣設計的。 第二個 this 是 global (在 browser 環境下是 window ) 這題非常基本,沒拿到分數請自我檢討 : 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, obj.1 不能用是因為不能用數字開頭 像你不能 var 1abc = 5 是一樣的。 這題非常基本,沒拿到分數請自我檢討 : 7.Please answer all below typeof: : typeof function(){} : typeof new Date() : typeof {} : typeof new Array() function object object object 這題非常基本,沒拿到分數請自我檢討 : 8.What do you think foo() is ? : if(1) function foo(){ return 'a'} : else function foo(){ return 'b'} : console.log( foo() ) 這題考得是 function scope ,這題就蠻有深度了。 答案是不管 if else 寫殺小, function 都會定義,所以一定是 'b'。 這題是很不錯得題目,能答對這題的一定都對 JS 很有 sense。 跟這題對稱的題目是 var foo ; if(1) { foo = function(){ return 'a'} } else { foo = function(){ return 'b'} } console.log( foo() ) 這時答案就會是 a 因為 function <functionName> (){} 這種 pattern 會額外的開外掛, 所以一般我會建議大家寫後面這種。 : 9.What is the console.log output? : function foo(){ : return this; : } : console.log( foo.call( foo ) ) function foo call 會 change context (this) : 10.Please explain what is the difference between "setTimeout()" and : "setInterval()" ? setTimeout(fn,duration) 是一次性的 setInterval(fn,duration) 是每隔 duration 會觸發的 這題非常基本,沒拿到分數請自我檢討 : 11.Please explain what the use of "preventDefault()" and ""stopPropagation()" : in Event Object ? 假設頁面是這樣 <div id="p"> <a href="" id="a" target="_blank">link</a> </div> 就以 a.onclick 來說明好了,點了一個超連結, 正常狀況下超連結會進行並開啟新頁, p 的 onclick 會被觸發(因為事件向上傳遞)。 --------------------------------- 如果在 a.onclick 裡面下 preventDefault() , a 的超連結就不會打開頁面。 如果在 a.onclick 裡面下 stopPropagation(), p.onclick 就不會觸發。 這題也是個很不錯的題目,很多人搞不懂這兩個的差別。 : 以上 就這幾題 : 至於是哪家公司的面試題目 我就不透漏了,透露出來好像不太好 -- 網頁上拉近距離的幫手 實現 GMail豐富應用的功臣 數也數不清的友善使用者體驗 這就是javascript 歡迎同好到 AJAX 板一同討論。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 182.235.118.79 ※ 編輯: TonyQ 來自: 182.235.118.79 (06/14 16:35)
TonyQ:註:第八題在 fx 上會有行為不同 06/14 17:05
※ 編輯: TonyQ 來自: 182.235.118.79 (06/14 17:14)
s25g5d4:對不起 我去檢討... 06/14 20:17
tails32100:該好好檢討一下了Orz 06/15 13:37
catspawboy:第六題 不需要xxx['1']嗎QQ? 06/17 16:58
catspawboy:不好意思 真的不用耶... 06/17 16:59
alpe:回去檢討... ... 06/17 17:18
grence:字串在什情況下會有值相等但型態不相等嗎 06/17 21:17
TonyQ:"1" == 1 雖然說是純數字才有的特例 XD 06/18 01:36
grence:剛還想到date,感覺會隱含呼叫 toString()的東西都有可能 06/18 01:52
grence:不過真的很難遇到XD 06/18 01:53
mrbigmouth:{} == '[object Object]' XDD 06/18 09:04
abgne:第三題應該是 D, 只有空字串是 false 07/05 17:04
TonyQ:it's not true , 題目出的不好. XD 07/05 22:39
chatnoir:非空字串轉成boolean好像都是true耶.. 12/17 13:32