truthiness Questions
7
Solved
I was expecting the following comparison to give an error:
var A = B = 0;
if(A == B == 0)
console.log(true);
else
console.log(false);
but strangely it returns false.
Even more strangely,
co...
Nessa asked 10/4, 2014 at 6:45
6
Solved
I understand that an empty string is falsy in javascript and a not-empty string is truthy in javascript.
However, why is 'false' truthy in javascript, is there anything explicit in the specificati...
Leodora asked 22/9, 2015 at 15:9
2
Solved
While it is always possible to use mixins or method overrides to modify the Bool coercions, by default what values are considered to be truthy and what values are considered to be falsy?
Note: this...
Melba asked 4/9, 2019 at 2:33
2
Solved
This question is spurred from the answers and discussions of this question. The following snippet shows the crux of the question:
>>> bool(NotImplemented)
True
The questions I have are ...
Blinkers asked 10/1, 2019 at 17:59
2
Solved
The empirical behaviour of my Perl 5.26.2 x64 (Cygwin) is that a dualvar is truthy if and only if its string part is truthy:
# Falsy number, truthy string => truthy
$ perl -MScalar::Util=dualva...
Rriocard asked 2/1, 2019 at 18:25
3
Solved
I am interested in the truth value of Python sets like {'a', 'b'}, or the empty set set() (which is not the same as the empty dictionary {}). In particular, I would like to know whether bool(my_set...
Kanchenjunga asked 28/6, 2017 at 22:13
4
Solved
I am learning python, but I'm a bit confused by the following result.
In [41]: 1 == True
Out[41]: True
In [42]: if(1):
...: print('111')
...:
111
In [43]: ... == True
Out[43]: False <=====...
Holland asked 11/5, 2017 at 14:47
2
Solved
I have seen the following cases:
>>> def func(a):
... if a:
... print("True")
...
>>> a = [1, 2, 3]
>>> func(a)
True
>>> a == True
False
Why does this d...
Assyriology asked 29/4, 2017 at 6:27
1
Solved
The documentation clearly states that
When this method (__bool__) is not defined, __len__() is called, if it is defined, and the object is considered true if its result is nonzero. If a cl...
Exoteric asked 9/2, 2017 at 20:39
4
Solved
import numpy as np
a = np.array([0])
b = np.array([None])
c = np.array([''])
d = np.array([' '])
Why should we have this inconsistency:
>>> bool(a)
False
>>> bool(b)
False
>...
Novena asked 5/5, 2015 at 3:44
1
In Groovy it is possible to test collections for null and empty simply by placing the variable by itself inside if like:
def collection = [ 'test' ]
if(!collection) {
//Collection is either null ...
Fix asked 16/2, 2015 at 20:20
1
Solved
Consider this code:
test_string = 'not empty'
if test_string:
return True
else:
return False
I know I could construct a conditional expression to do it:
return True if test_string else False...
Spoonbill asked 4/12, 2014 at 0:54
2
Solved
In angular.js, there are some code snippets use !! to check whether a value is truthy in if condition.
Is it a best practice? I fully understand in return value or other assignment !! is used to m...
Resht asked 13/11, 2014 at 10:12
2
One of the limitations of PHP is that objects always evaluate to true. However SplFileinfo (and subclasses such as Symfony's UploadedFile) behave differently:
$a = new ArrayIterator(); // or any o...
Interrupter asked 5/7, 2013 at 12:14
1
Solved
In IE and Chrome, typing this into the JavaScript console throws an exception:
{} == false // "SyntaxError: Unexpected token =="
However, all of these statements are evaluated with no problem:
...
Swanee asked 22/5, 2014 at 1:50
6
Solved
In reading about Perl 6, I see a feature being trumpeted about, where you no longer have to do:
return "0 but true";
...but can instead do:
return 0 but True;
If that's the case, how does tru...
Participate asked 24/9, 2008 at 3:30
2
Solved
Let's say I have a something like
true && true #=> true
Which makes sense, so I try something like:
true && "dsfdsf" #=> "dsfdsf"
Which surprises me because often times ...
Enrica asked 28/3, 2014 at 15:7
2
Solved
I've been reading about JavaScript hoisting sometime back.
JavaScript Scoping and Hoisting by Ben Cherry
Two words about “hoisting” by Dmitry Soshnikov
and, some more about JavaScript type-coercio...
Eugenie asked 20/7, 2011 at 17:37
4
Solved
Is it normal for methods with a question mark to return something that's truthy (for example, a number) to indicate that something is true, or should true itself be returned?
Are there any example...
Eligibility asked 27/11, 2010 at 1:36
1
© 2022 - 2024 — McMap. All rights reserved.