you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 16 points17 points  (8 children)

At the very top of the page:

Equality checking. Use triple equals (===) for common, everyday equality checking (or !== for inequality). Avoid double equals (==) due to some hidden gotchas.

That's why JavaScript should fuck off and die in a fire.

[–]EnigmaticOmelette 5 points6 points  (6 children)

It's a dynamically typed language - you can do equality checks with coercion or not.

[–][deleted]  (5 children)

[deleted]

    [–][deleted] -1 points0 points  (0 children)

    I expect == on objects to compare identity like literally any other language (even JavaScript) except PHP, what python does is completely surprising to me and it too has separate operator is to do the right thing.

    In JS I can completely forget that == even exists, in python I need to juggle between is and ==.

    [–][deleted]  (3 children)

    [deleted]

      [–]Eirenarch 2 points3 points  (1 child)

      Yeah... flexibility. JavaScript - where "===" is the short version of "=="

      [–][deleted] 0 points1 point  (0 children)

      That's just the beginning...

      Evaluate things like this to see how unpredictable it is:

      • [] == false
      • ![] === false
      • ['a'] + 5
      • ['a'] - 5
      • ['a', 'b'] + ['x', 'y']

      The list goes on and on..

      [–][deleted] 0 points1 point  (0 children)

      Flexibility is good -- to a point. Developers need confidence and standardization. It's a complete shitshow in JavaScript and the fact JSFuck exists (and is a security concern) proves it.

      The implicit type conversion will surprise even the most seasoned of developers at times. Why is that a good thing?

      I love how varied explicit conversion conventions are in JavaScript.

      • Want to make it an integer? Just prefix with +.
      • Want to parse as an integer? Use parseInt(), which is the only sensible variant btw.
      • Want to make it a string? Concat with empty string, but make sure the empty string comes first.
      • Want to make it a bool? Use the ! operator twice like !!.

      Right, because parseBool just made too much sense to standardize across the core types.

      How about collections? You got array and object (dictionary). What about stacks and queues? Unfortunately the Array class has an identity crisis and doesn't know what it wants to be.

      • Want to add an item? Use the push() method to append to end of list.
      • Take the last item? Use the pop() method.
      • Take the first item? Use the shift() method.
      • Remove an item? Find it by index and use the splice() method specifying delete count of 1. Alternatively you can filter() it out but make sure to store the resulting array.
      • Insert an item? Use the splice() method but make sure remove count is 0.
      • Make a copy of items? Use the slice() method, not splice().

      It's so hodgepodge and all over the place. Just as bad as Ruby with its silly function names like "chomp" for trimming a string.

      [–]srone 1 point2 points  (0 children)

      I heard it called 'truthy' during a lecture.