JavaScript-Equality-Table | JavaScript equality comparison is a crazy thing | Learning library
kandi X-RAY | JavaScript-Equality-Table Summary
kandi X-RAY | JavaScript-Equality-Table Summary
JavaScript equality comparison is a crazy thing, sometimes. When in doubt, use three equals signs.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of JavaScript-Equality-Table
JavaScript-Equality-Table Key Features
JavaScript-Equality-Table Examples and Code Snippets
Community Discussions
Trending Discussions on JavaScript-Equality-Table
QUESTION
I use Chrome browser 60.x, and test the code isNaN([3])
.
The result is false
, but I cannot understand it.
[3]
is an Array, and it is not empty.
I think [3]
is array object, and it is not an number.
Otherwise the result of isNaN(["ABC"])
is true
.
And another result of isNaN([1,2,3])
is true
.
So I guess javascript engine is force changing array to number which the array has a single element.
Please let me know what is happened isNaN
function for array parameter.
ref1: Why is isNaN(null) == false in JS?
ref2: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN
[EDIT] Thank you everyone for answering.
I understand javascript parsed the value implicitly before comparison.
And I found a useful link while reading Nina Scholz's answer.
The comparison table : http://dorey.github.io/JavaScript-Equality-Table/
ANSWER
Answered 2017-Sep-04 at 07:20When you use isNaN
it tries to parse your input value into the number
and then checks if it is NaN
or not.
See some examples.
For an array with one item, the Number()
function returns an object, which actually hold the first item as a value (see console.log
). For many items it returns NaN
, so you get isNaN
's result -> true
.
QUESTION
I'm getting and object from the back-end with some properties and use AngularJS to put them into input fields (inputs, textareas, checkboxes, dropdown lists).
These properties are in some cases a text value, in some a number value but can also be null
, undefined
, false
or ""
.
I clone this object and then check if user is making any modifications to each of these values by comparing the old (stored) value with new (current) one.
I don't want to use the ng-dirty
class for detecting a change because it does not disappear when you go back to the previous value after a prior modification (e.g. when using Ctrl+Z).
I thought this task would be simple however I'm getting trouble with this due to ambiguous nature of JS values.
Of course I treat every of these:
null
undefined
false
""
an "empty value" because for user "an empty field is an empty field", regardless of what the model stores underneath. So, for example, a change from undefined
to ""
is not really a change.
So far I've got this:
...ANSWER
Answered 2017-Apr-03 at 13:03You could use exclusive OR and check the values with
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install JavaScript-Equality-Table
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page