In dynamically typed language, truthiness is a term used to describe a value that might evaluate to boolean true.
Questions tagged [truthiness]
99 questions
2
votes
3 answers
Javascript: using "!!" in boolean context
Is there any reason to use !!someValue (which is equivalent to Boolean(someValue)) in a boolean context? In other words, in situations like if (someValue) ..., does it make sense to write if (!!someValue) ...?
It hurts my eyes and I think it's…

noamtm
- 12,435
- 15
- 71
- 107
2
votes
3 answers
Whats the difference between the following conditions in TypeScript?
if (!value || value.length<1)
if (value.length<1)
What's the difference between the two conditions? Wouldn't it be same?

user3082488
- 61
- 6
2
votes
1 answer
Using Comparison (< >) Operators With Non-Numeric Strings in Javascript
I'm trying to figure out exactly what is happening when I compare a number to a non numeric string in javascript with the < or > operator.
When I make the following comparisons in JS
console.log(0 > "y")
console.log(5000 > "y")
console.log(-3 >…

Luke
- 1,736
- 2
- 16
- 34
2
votes
2 answers
Python OR for list
In Python you can do
print (0 or None or False or "" or [] or "hello" or None or "bar")
which will print
hello
Can you do the same with a list? I.e. is there a Python function foo so that the following will also print hello?
print (foo([0, None,…

oyvind
- 1,429
- 3
- 14
- 24
2
votes
3 answers
What is the simplest way to compare truthiness in this specific way?
Given the following instructions I have created a function that achieves the requirements. I feel my function is a bit too complex, though it does what it's supposed to. The difficult part for myself was avoiding the equality operators. The only way…

CalamityAdam
- 354
- 1
- 6
- 15
2
votes
2 answers
Python 3 lambda error: The truth value of a Series is ambiguous
I am getting this error: The truth value of a Series is ambiguous in my lambda function. I know that here is a very comprehensive explanation around this error but I don't think this relates to my issue:
Truth value of a Series is ambiguous. Use…

GivenX
- 495
- 1
- 8
- 17
2
votes
3 answers
Understanding the truthiness of strings
I understand that Python built-in types have a "truthiness" value, and the empty string is considered False, while any non-empty string is considered True.
This makes sense
I can check this using the built-in function bool.
>>> bool("")
False
>>>…

Dustin Michels
- 2,951
- 2
- 19
- 31
2
votes
2 answers
Using conditional statement to subtract scalar from pandas df column gives ValueError: The truth value of a Series is ambiguous
I'm trying to execute:
if df_trades.loc[:, 'CASH'] != 0: df_trades.loc[:, 'CASH'] -= commission
and then I get the error. df_trades.loc[:, 'CASH'] is a column of floats. I want to subtract the scalar commission from each entry in that column.
For…
user2398046
2
votes
0 answers
Javascript - what is true in if statements
I'm a bit confused by what is considered true in an if statement in javascript.
Example:
if (object.property) {
// stuff...
}
Under which circumstances will the content of this statement be executed? Are there any browser differences in…

Johan Dahl
- 1,672
- 3
- 19
- 35
2
votes
1 answer
Evaluating truthy values
I wanted to say something like:
if field_1 then set field_2 = 1
Meaning, if field_1 holds a truthy value, do something else. Can an IF statement in sql execute this kind of evaluation?

Joseph Erickson
- 938
- 3
- 8
- 24
2
votes
5 answers
How to evaluate string as boolean in return statement?
I have a function like this in Python 3.4:
def is_value_valid(the_str):
return len(the_str) != 0
There are of course other ways to write this, such as return the_str != "". Are there more pythonic ways of writing this expression? I am familiar…

void.pointer
- 24,859
- 31
- 132
- 243
2
votes
5 answers
Is an empty array always interpreted as TRUE?
Is this the case in all browser versions? Meaning, an empty array is always considered as TRUE and never as FALSE as a boolean representation?
var x = [];
if(x)
alert('this could be an empty array');
else
alert('this could NEVER be an empty…

Simon Ferndriger
- 4,455
- 6
- 28
- 53
2
votes
4 answers
if(negetive number) is true? Is something wrong with js?
Is something wrong with js?
if("hello".indexOf("world")) { // I forgot to add > -1 here
console.log("hello world");
}
Basically if(-1) is true. How is this possible? It took me a whole day to fix this. Is there a list available where these kind…

bhb
- 2,476
- 3
- 17
- 32
2
votes
2 answers
What is the bash equivalent of Python's all?
In a part of a bash script I'm writing, I'd like to check if any of the variables in a list are unset.
In Python, there is a built-in function all that returns True if all elements in an iterable are true:
>>> all([True, 1, "foo"])
True
>>>…

3cheesewheel
- 9,133
- 9
- 39
- 59
1
vote
1 answer
How to return a date/datetime object rather than an expression of that type?
I want to declare a start and end date variable (date/datetime dtype, preferably using Polars), and then to run a while loop where the condition is that startdate <= enddate (each loop raising the value of startdate by one day).
Here's my…

Balthazar
- 81
- 9