javascript - if(negetive number) is true? Is something wrong with js? -


is wrong js?

if("hello".indexof("world")) { // forgot add > -1 here     console.log("hello world"); } 

basically if(-1) true. how possible? took me whole day fix this. there list available these kind of things listed? or tools available catch things these.

as per ecma 5.1 standard specifications, following table used determine truthyness of expression

+-----------------------------------------------------------------------+ | argument type | result                                                | |:--------------|------------------------------------------------------:| | undefined     | false                                                 | |---------------|-------------------------------------------------------| | null          | false                                                 | |---------------|-------------------------------------------------------| | boolean       | result equals input argument (no conversion). | |---------------|-------------------------------------------------------| | number        | result false if argument +0, −0, or nan;| |               | otherwise result true.                         | |---------------|-------------------------------------------------------| | string        | result false if argument empty      | |               | string (its length zero); otherwise result  | |               | true.                                                 | |---------------|-------------------------------------------------------| | object        | true                                                  | +-----------------------------------------------------------------------+ 

Comments

Popular posts from this blog

Why can rails not find a route created by a helper? -

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -