VehiclesFashionRecipesBlogsHuntTravelsSportFunHandmadeITEducation
Mini-Games
x

x
zakruti.com » IT - Software » freeCodeCamp.org
Logical operators && TRICKS with short-circuit evaluation - Beau teaches JavaScript

Logical operators && TRICKS with short-circuit evaluation - Beau teaches JavaScript

FBTwitterReddit

video description

Rating: 4.0; Vote: 1
Short-circuit evaluation happens when using conditionals with && or --. The second argument is only evaluated when the first argument is not enough to determine the value of the expression. Learn some tricks using short-circuit evaluation in JavaScript. Code: - http://codepen.io/beaucarnes/pen/jyGYQX?editors=0012 More info: - http://www.jstips.co/en/short-circuit-evaluation-in-js/ Beau Carnes on
Date: 2022-03-14

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

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

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