2011-09-17 3 views
17

가능한 중복 :
What is the !! operator in JavaScript?
What does !! (double exclamation point) mean?이중 느낌표는 무엇입니까 !! 연산자 뜻?

나는 일부 사용자 지정을 통해려고하고 내 직장에서 자바 스크립트 코드와 나는 다음과 같은 구조를 이해할 수 없습니다입니다.

var myThemeKey = (!!$('row') && $('row').hasClassName('green-theme')) ? 'green' : 'white'; 

나는 !! 연산자를 제외한 위의 줄에 모든 것을 이해합니다. 나는 그것이 NOT 연산자라고 가정하고 NOTNOT 인 것은 원래 값이지만 누군가가 NOTNOT으로하는 이유는 무엇입니까?

누군가 위의 코드 줄에서 어떤 일이 벌어지고 있는지 이해할 수 있도록 도와 줄 수 있습니까?

+0

http://stackoverflow.com/questions/784929/what-is-the-operator-in-javascript –

+0

http://stackoverflow.com/questions/784929/what-is-the-operator-in -javascript –

+0

http://stackoverflow.com/questions/784929/what-is-the-operator-in-javascript – Josh

답변

44

!!은 결과 유형이 부울 (true 또는 false)인지 확인합니다.

javascript:alert("foo") ->foo

javascript:alert(!"foo") ->false

javascript:alert(!!"foo") ->true

javascript:alert(!!null)은 -> 그들은이 있는지 확인하기 위해 할

false$('row')은 아니다 없는.

$('row') != null ? true : false보다 짧습니다.

+1

감사합니다.이 답변은 정말 도움이됩니다 .. – stirfries