Linked Questions

0 votes
7 answers
2k views

edit : Quote removed. is not related to the question. Question How come does it always (when all are truthy) takes the last value ? Examples : f= 1 && 2 && 3 //3 f= 'k' &&...
Royi Namir's user avatar
  • 149k
1 vote
6 answers
2k views

I got asked this question recently in an interview. I know that in JavaScript evaluation goes left to right. 1&&2 should be false right? I read in another ask here that 1&&2 returns 2....
Nandhini A's user avatar
1 vote
1 answer
2k views

Here is the function I am working with. I actually found it in React Native documentation : var testFunction = function(word) { return word && '🍕'; } Here is how I am using this function : ...
Alexandre Bourlier's user avatar
1 vote
2 answers
3k views

I had checked for many test cases. It's looking if the first value is true and it's returning the second value. Example: 2 && 5 // --> 5 5 && 10 // --> 10 0 && 2 // --&...
Chethan kumar B N's user avatar
2 votes
1 answer
746 views

var operand1 = null; var operand2 = true; var booleanOperatorReturnsABoolean = operand1 && operand2; booleanOperatorReturnsABoolean == false || booleanOperatorReturnsABoolean == true Result: ...
Jonathan's user avatar
  • 7,178
4 votes
2 answers
2k views

I wrote the following Javascript function that is meant to return true when exactly one of the arguments is truthy: function onlyOne( a, b, c) { return (a && !b && !c) || (...
Chad's user avatar
  • 2,000
0 votes
2 answers
2k views

There is one interview question below. The logical AND of two truths should be true. But the output is 3. Why? var a = 2; var b = 3; var c = a && b; // value of c = 3 console.log(...
BILAL AHMAD's user avatar
0 votes
3 answers
97 views

I understand a||b returns an object, not boolean value. I just can't figure out why javascript gives different results for undefined || "" (result is "") "" || undefined (result is undefined) which I ...
AlliceSmash's user avatar
1 vote
2 answers
580 views

I am trying to figure out why this javascript function returns 0 when this.position.startOffset value is 0 but not when the value is a number other than 0. ready: function() { return (this....
Taylor's user avatar
  • 1,253
3 votes
2 answers
184 views

Imagine this simple scenario. I have variable that can be plain JS object with one property, ID, that is a number or obj variable can be null. I have simple test() function that checks if the variable ...
Tjodalv's user avatar
  • 370
2 votes
1 answer
211 views

I just ran across this code var someBool = !!(o.a && o.a.t); I was about to remove the double-negation, then realized it forces someBool to be a boolean value... Looking on the MDN, I find ...
quickshiftin's user avatar
  • 70.4k
1 vote
2 answers
423 views

I get a boolean return when checking for a falsy value, but not a boolean when checking for a truthy value... I am just getting a string instead. This works. const isFalse = !values.firstName &&...
Grateful's user avatar
  • 10.4k
1 vote
1 answer
58 views

Let's take a look at this code: var token = (req.body && req.body.access_token) || (req.query && req.query.access_token) || req.headers['x-access-token']; ...
Kenny's user avatar
  • 4,612
0 votes
1 answer
69 views

I have something like the following: var val = "string"; var testVal = val && val.length; I would expect testVal to be either true or false but it is the length of the string. Not sure why ...
user avatar
0 votes
0 answers
60 views

Related to coerce and default values in JavaScript, given this code: function greet(name){ name = name || ''; console.log("Hello " + name); } greet(); Not given any name as parameter, we have ...
Rafa Romero's user avatar
  • 2,736

15 30 50 per page