Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does 'v !== v' expression check?

Tags:

javascript

I have seen this in the sources of one lib, and confused. I think, it always evaluates to 'false'. What is the meaning of using that?

like image 695
user179437 Avatar asked Jul 11 '12 10:07

user179437


People also ask

What does V-show do?

The v-show directive is a Vue. js directive used to toggle the display CSS property of a element with our data via inline styles. If the data is true it will make it visible else it will make it invisible.

What does V-bind do?

The v-bind directive is a Vuejs directive used to bind one or more attributes, or a component prop to an element. If that attribute is binded to our data defined in Vuejs instance then dynamically changes can be observed as data changes.

What is the difference between V-if and V-show?

The key difference is that v-if conditionally renders elements and v-show **conditionally displays **elements. This means that v-if will actually destroy and recreate elements when the conditional is toggled. Meanwhile, v-show will always keep the element in the DOM and will only toggle its display by changing its CSS.

What is V cloak?

The v-cloak directive is a Vue. js directive that will remain on the element until the associated Vue instance finishes compilation. Combined with CSS rules such as [v-cloak] { display: none }, this directive can be used to hide uncompiled mustache bindings until the Vue instance is ready.


1 Answers

It checks whether v is NaN:

if( v !== v ){
    //'v' is NaN   here
}

From standard:

A reliable way for ECMAScript code to test if a value X is a NaN is an expression of the form X !== X. The result will be true if and only if X is a NaN.

Why not just use built-in isNaN()?

The answer is simple: "isNaN() is not reliable enough.". Here are the cases, when isNaN() will be failed:

isNaN("NaN")         //true
isNaN(undefined)     //true
like image 122
Engineer Avatar answered Oct 04 '22 19:10

Engineer