Git Product home page Git Product logo

Comments (20)

panzerdp avatar panzerdp commented on May 29, 2024

Comment written by Eric on 01/14/2016 23:40:26

Well documented!

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 29, 2024

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.

panzerdp avatar panzerdp commented on May 29, 2024

Comment written by Dmitri Pavlutin on 03/08/2016 05:06:25

You're welcome.
Yes, the evaluation is correct.

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 29, 2024

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.

panzerdp avatar panzerdp commented on May 29, 2024

Comment written by Dmitri Pavlutin on 04/11/2016 08:55:53

I'm glad that you like it. Thanks.

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 29, 2024

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.

panzerdp avatar panzerdp commented on May 29, 2024

Comment written by Harjot Sahota on 04/28/2016 06:12:38

Very clear explanation. Thank you.

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 29, 2024

Comment written by William Young on 04/28/2016 10:39:29

[0] == 0
"0"==0
0==0
True

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 29, 2024

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.

panzerdp avatar panzerdp commented on May 29, 2024

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.

panzerdp avatar panzerdp commented on May 29, 2024

Comment written by Dmitri Pavlutin on 05/06/2016 07:32:05

I'm glad the explanation helped you. Thanks!

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 29, 2024

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.

panzerdp avatar panzerdp commented on May 29, 2024

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.

panzerdp avatar panzerdp commented on May 29, 2024

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.

panzerdp avatar panzerdp commented on May 29, 2024

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.

panzerdp avatar panzerdp commented on May 29, 2024

Comment written by Marek on 05/19/2016 06:36:16

Thanks for the quick reply! Now everything's clear.

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 29, 2024

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.

panzerdp avatar panzerdp commented on May 29, 2024

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.

panzerdp avatar panzerdp commented on May 29, 2024

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.

panzerdp avatar panzerdp commented on May 29, 2024

Comment written by Artur Mostowiak on 10/28/2019 12:53:32

Nice

from dmitripavlutin.com-comments.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.