
Logical operators && TRICKS with short-circuit evaluation - Beau teaches JavaScript
video description
Date: 2022-03-14
Related videos
Comments and reviews: 3
------
Can anyone help me??
I followed typing code in Chrome console window which is
var test = true;
var isTrue = function()-
console.log('Test is true.');
-;
var isFalse = function()-
cosole.log('Test is false.');
-;
test = false
if (!test)-
isFalse();
-
and when I click enter, the response for my code is
-Uncaught ReferenceError: cosole is not defined
at isFalse (:8:4)
at :2:5-
I cannot find out the reason why 'is False' is not defined.
I think there is no one have a problem like me,,,,--
please tell me why,,,--
sorry for my bad english.
Thanks!!!
reply
Can anyone help me??
I followed typing code in Chrome console window which is
var test = true;
var isTrue = function()-
console.log('Test is true.');
-;
var isFalse = function()-
cosole.log('Test is false.');
-;
test = false
if (!test)-
isFalse();
-
and when I click enter, the response for my code is
-Uncaught ReferenceError: cosole is not defined
at isFalse (:8:4)
at :2:5-
I cannot find out the reason why 'is False' is not defined.
I think there is no one have a problem like me,,,,--
please tell me why,,,--
sorry for my bad english.
Thanks!!!
reply
SogMosee
Is it possible to use short-circuit evaluation with multiple variables? I would think so, but for some reason, this fails:
let amountLength = transactionAmountField.value.length === 0,
methodLength = methodSelect.value.length === 0,
categoryLength = categorySelect.value.length === 0,
disable = () => transactionSubmitButton.disabled = true,
activate = () => transactionSubmitButton.disabled = false
(amountLength -- methodLength) && disable()
The disable function is not called despite both amountLength and methodLength being equal to 0.
reply
Is it possible to use short-circuit evaluation with multiple variables? I would think so, but for some reason, this fails:
let amountLength = transactionAmountField.value.length === 0,
methodLength = methodSelect.value.length === 0,
categoryLength = categorySelect.value.length === 0,
disable = () => transactionSubmitButton.disabled = true,
activate = () => transactionSubmitButton.disabled = false
(amountLength -- methodLength) && disable()
The disable function is not called despite both amountLength and methodLength being equal to 0.
reply
Carlos
You know what's lacking? to explain the caution when using short circuit evaluation when assigning a boolean, what if you expect a boolean but you just want to avoid having null or undefined?
reply
You know what's lacking? to explain the caution when using short circuit evaluation when assigning a boolean, what if you expect a boolean but you just want to avoid having null or undefined?
reply
Add a review, comment
Other channel videos















