Created
January 17, 2020 14:11
-
-
Save JH108/5ded3ae902b9837e7a4949c6ba167c34 to your computer and use it in GitHub Desktop.
Random stuff that is valid JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = null; | |
function b(c) { var d = ['abc']; return d.find(e => e === c)} | |
if (Boolean(a)) console.log('True'); // True | |
if (!Boolean(a)) console.log('True'); // nothing | |
b('h') // undefined | |
b('abc') // abc | |
if (Boolean((a = b('abc')))) console.log('True', a); // True abc | |
if (Boolean((a = b('abcd')))) console.log('True', a); // nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think the goal here was to demonstrate variable reassignment within the evaluation of an
if
statement. The use case was thatfunction b
was an expensive function that I only wanted to run once but I needed to assign the result to variablea
only if the function returned a valid result.