I think we need all support we can get to fight Google on this, so I welcome Brave here actually.

Use this link to avoid going to Twitter:

https://nitter.kavin.rocks/BrendanEich/status/1684561924191842304

you are viewing a single comment's thread
view the rest of the comments
[–] 4 points 3 years ago (4 children)

JS is one of the most fun programming languages ever created; how dare you slander its great name.

  • source
  • parent
  • hideshow 4 child comments
  • [–] 5 points 3 years ago* (3 children)

    sure mate, just tell me the result of the following without trying it out.

    0 && 1 && false

  • source
  • parent
  • hideshow 3 child comments
  • [–] 3 points 3 years ago* (2 children)

    If I remember correctly, 0 and 1 are considered falsy and truthy respectively, so it should be falsy and truthy and false which I believe would return false.

    Tried it out to double-check, and the type of the first in the sequence is what ultimately is returned. It would still function the same way if you used it in a conditional, due to truthy/falsy values.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 3 years ago* (1 child)

    yes, that is a solid logic, one that I also applied and expected to be the result.

    that is until a Vue component started complaining that I am passing in a number for a prop that expects a boolean.

    turns out the result of that code is actually: 0, because javascript

    of course if you flip it and try

    false && 0 && 1

    then you get false, because that's what you really want in a language, where && behaves differently depending on what is on what side.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 2 points 3 years ago* (last edited 3 years ago)

    I was incorrect; the first part of my answer was my initial guess, in which I thought a boolean was returned; this is not explicitly the case. I checked and found what you were saying in the second part of my answer.

    You could use strict equality operators in a conditional to verify types before the main condition, or use Typescript if that's your thing. Types are cool and great and important for a lot of scenarios (used them both in Java and Python), but I rarely run into issues with the script-level stuff I make in JavaScript.

  • source
  • parent