Comments (20)
Comment written by Eric on 01/14/2016 23:40:26
Well documented!
from dmitripavlutin.com-comments.
Comment written by Charles Robertson on 03/07/2016 21:28:30
Brilliant article. Thank you:
[0] == 0
-> 0 == 0 // true
from dmitripavlutin.com-comments.
Comment written by Dmitri Pavlutin on 03/08/2016 05:06:25
You're welcome.
Yes, the evaluation is correct.
from dmitripavlutin.com-comments.
Comment written by Peshmerge on 03/29/2016 14:40:55
[0] == 0, object will be converted to primitive data type so it will be like this " 0==0 " and that is true :)
Very helpful article. Thank you very much :)
from dmitripavlutin.com-comments.
Comment written by Dmitri Pavlutin on 04/11/2016 08:55:53
I'm glad that you like it. Thanks.
from dmitripavlutin.com-comments.
Comment written by Deepak Sai on 04/24/2016 18:47:44
Dmitri ,,, thanks for you and your time for sharing this, really a good JS
article ...
from dmitripavlutin.com-comments.
Comment written by Harjot Sahota on 04/28/2016 06:12:38
Very clear explanation. Thank you.
from dmitripavlutin.com-comments.
Comment written by William Young on 04/28/2016 10:39:29
[0] == 0
"0"==0
0==0
True
from dmitripavlutin.com-comments.
Comment written by Ravinder Kumar on 05/06/2016 07:28:05
[0] == 0;
'0'==0;
0==0;
0===0; //true;
from dmitripavlutin.com-comments.
Comment written by Ravinder Kumar on 05/06/2016 07:30:20
You really helped me to understand 'stone age' well. Done a great job.
from dmitripavlutin.com-comments.
Comment written by Dmitri Pavlutin on 05/06/2016 07:32:05
I'm glad the explanation helped you. Thanks!
from dmitripavlutin.com-comments.
Comment written by loopmode on 05/15/2016 10:07:17
"If one operand is number and another is a string, convert the string to number. Compute the comparison again"
Seems inefficient, or am I missing something? I wonder why not convert the number to string, which works always, while string to number can obviously fail in n cases..
from dmitripavlutin.com-comments.
Comment written by Dmitri Pavlutin on 05/15/2016 15:47:41
Interesting question.
The equality is transforming operators to numbers (if one of it is a number) to deal with different formats that a number can have. For example:
'1.0' == 1
It makes sense to transform '1.0' into a number, then compare 1.0 === 1
which is true
.
If transforming both operands to string, '1.0' == '1' is false, which is not quite expected.
from dmitripavlutin.com-comments.
Comment written by Marek on 05/18/2016 12:16:29
Do if statements work differently ? Having {} == true // false why does if ({}) evaluate to true?
from dmitripavlutin.com-comments.
Comment written by Dmitri Pavlutin on 05/18/2016 13:01:31
Hi Marek.
Yes, if ({} == true) { }
and if ({}) { }
are evaluated differently by JavaScript.
The first case you can find described in the example 7. It evaluates to false
.
The second case doesn't involve any comparison operators. The condition is passed because the object literal {} is a truthy value.
Falsy values in JavaScript are considered '', null, undefined, NaN, 0, false. All other ones are truthy, including objects (like {}), true, 1, etc.
Thanks for your interesting question.
from dmitripavlutin.com-comments.
Comment written by Marek on 05/19/2016 06:36:16
Thanks for the quick reply! Now everything's clear.
from dmitripavlutin.com-comments.
Comment written by Suresh Raj on 06/12/2016 04:49:28
Hi Dmitri, another great in depth article. I have doubt in "The equality operator example 2" section,
how js transform ' ' into number 0 ? Because parseInt('') return NaN.
from dmitripavlutin.com-comments.
Comment written by Dmitri Pavlutin on 06/12/2016 05:25:55
Hi Suresh. In equality, JavaScript uses Number()
function to transform a string into an integer. This way Number('')
is 0
.
from dmitripavlutin.com-comments.
Comment written by Artur Mostowiak on 02/01/2018 21:14:41
Also good and short explanation. Keep up with a good work :)
from dmitripavlutin.com-comments.
Comment written by Artur Mostowiak on 10/28/2019 12:53:32
Nice
from dmitripavlutin.com-comments.
Related Issues (20)
- react-usememo-hook/ HOT 12
- javascript-json-modules/ HOT 7
- javascript-import-meta/ HOT 3
- javascript-array-group/ HOT 16
- javascript-array-flatmap/ HOT 23
- interface-vs-implementation/ HOT 11
- vue-next-tick/ HOT 4
- props-destructure-vue-composition/ HOT 7
- ref-reactive-differences-vue/ HOT 5
- environment-variables-javascript/ HOT 3
- ref-in-vue/ HOT 1
- typescript-function-type/ HOT 5
- vue-v-model-form-inputs/ HOT 2
- react-forwardref/ HOT 4
- javascript-enum/ HOT 19
- react-comments/ HOT 8
- typescript-record/ HOT 10
- screen-window-page-sizes/ HOT 3
- javascript-pure-function/ HOT 1
- Great article
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dmitripavlutin.com-comments.