李立峰 Posted August 20, 2015 Share Posted August 20, 2015 What does !! in javascript mean? I cannot find it in http://www.w3schools.com/js/js_operators.asp And also, where can I look up these operators? You know, typing operators (like !!) in Google normally returns nothing.. Thanks! Link to comment Share on other sites More sharing options...
dsonesuk Posted August 20, 2015 Share Posted August 20, 2015 Google search 'double exclamation operator' instead Link to comment Share on other sites More sharing options...
Ingolme Posted August 20, 2015 Share Posted August 20, 2015 It's actually on this page in the section about logical operators: http://www.w3schools.com/js/js_comparisons.asp If it helps to understand it better, !!something is the same as !(!something) Link to comment Share on other sites More sharing options...
justsomeguy Posted August 20, 2015 Share Posted August 20, 2015 To put it more simply, "!!" is not one operator, it is two operators being used at once. Link to comment Share on other sites More sharing options...
dsonesuk Posted August 21, 2015 Share Posted August 21, 2015 ! on its own by default with boolean variable like if(!something) would check if value is NOT true (I.E false), adding second if(!!something) would reverse previous comparison to check value IS true, so as you add more exclamation marks it would give opposite comparison to previous, NOT true, IS true, NOT true and so on.... Where if(!something) //not true or if(something) // is true would suffice Link to comment Share on other sites More sharing options...
justsomeguy Posted August 21, 2015 Share Posted August 21, 2015 The main purpose is to cast something as a boolean. e.g.: var obj = {prop: 'val'}; // this is an objectvar bool = !!obj; // this is a boolean, true if obj is not a "falsy" value Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now