Nice post, I wouldn't have thought about using an "invisible" character.
Now, for the curious people, there is also another way :)
const a = { valueOf: (function(){ let x = 1; return () => x++; })() } console.log(a == 1 && a == 2 && a == 3); // => true
Just for reference, the concepts used here are type coercion, closures and immediate function invocation.
Regards
p.s. can a === 1 && a === 2 && a === 3 evaluate to true?
a === 1 && a === 2 && a === 3
true
Nice! Way more useful and interesting than the actual post.
This is very cool and scary!
Yes, you also can make true from a === 1 && a === 2 && a === 3 without invisible character, since, we have getter.
let i = 0; Object.defineProperty(window, 'a', { get: function() { return ++i; } }); console.log(a === 1 && a === 2 && a === 3);
Precisely, nice catch.
Nice, interesting approach!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nice post, I wouldn't have thought about using an "invisible" character.
Now, for the curious people, there is also another way :)
Just for reference, the concepts used here are type coercion, closures and immediate function invocation.
Regards
p.s. can
a === 1 && a === 2 && a === 3
evaluate totrue
?Nice! Way more useful and interesting than the actual post.
This is very cool and scary!
Yes, you also can make true from
a === 1 && a === 2 && a === 3
without invisible character, since, we have getter.Precisely, nice catch.
Nice, interesting approach!