Questions tagged [truthy]

If `not(x)` is the Boolean negation function of a programming language, then a value, x, may be said to be truthy in that language if and only if not(not(x)) evaluates to the Boolean value `true`.

Truthiness is a concept introduced into R by the Shiny UI framework. "The terms "truthy" and "falsy" generally indicate whether a value, when coerced to a base::logical(), is TRUE or FALSE." (see the Shiny reference). It has mostly been in invented to check if the GUI delivers a valid user input but is useful in R in many other situations, too.

11 questions
11
votes
2 answers

What is the difference between truthy and falsy with true and false in JavaScript?

I have a question concerning some concepts in JavaScript such as (truthy, true) and (falsy, false). I know the type of 1 is not true but the question is: why 1 == true? What was the main reason of ECMAScript to consider 1 or "ghsagh" as true? I also…
Amir Jalilifard
  • 2,027
  • 5
  • 26
  • 38
2
votes
1 answer

PHP - what is the point of using isSet() and checking for truthy value?

I saw this in my codebase today: if (isset($purchase_data['buyer_tracking_address_id']) && $purchase_data['buyer_tracking_address_id']) { // do something } Why would checking for both conditions be necessary? Isn't using just the first clause…
David Pham
  • 187
  • 1
  • 4
  • 14
2
votes
2 answers

How to check if variable is not falsy but 0 passes in Javascript

Is there an elegant way to check if variable is NOT falsy but in case of 0 it passes. The issue with this way of verifying if(var !== undefined && var !== null) is that it's long and doesn't cover all cases like undecalred or NaN. I'm also using…
valentin Ivanov
  • 83
  • 1
  • 10
2
votes
1 answer

Python Pandas & operator not returning right values

In the code: df = pd.DataFrame([[False, 0], [False, 1], [False, 2], [False, 2], [False, 3], [False, 4], [False, 5]], columns=['cond1', 'cond2']) df['test'] = (~df['cond1']) & (df['cond2']) I'm expecting to get in the test column the value…
Aryerez
  • 3,417
  • 2
  • 9
  • 17
2
votes
1 answer

How to select a subset of elements of the input R6 class within a shiny module to perform operations on them

Can I access a list of all input widgets within a module (let us name it myModule) and check if their state is isTruthy(). I found a way that works when I know (or can deduce) the exact names of the widgets (see 1). All_Inputs <-…
Jan
  • 4,974
  • 3
  • 26
  • 43
1
vote
2 answers

Strange behaviour of the alternative operator //

Using JQ 1.5 I've problems understanding the output of the alternative operator // in a specific situation. Given this input: { "a": 42, "b": false, "c": null } I expected the expression (.a, .b, .c, .d) // -1 to return…
A.H.
  • 63,967
  • 15
  • 92
  • 126
1
vote
1 answer

Using the boolean "True" as an expression to evaluate in a while loop

I recently was making a little script that would ask for tv series titles and logs them on the console in an array. I used a keyword to stop the loop which is 'terminate' and it should not be included, however, the following code adds the keyword to…
1
vote
2 answers

How can I check this function for truthy or return an empty array if falsy?

I am looking at this assignment, and my question is about the part in bold at the end: // Do not edit the code below. var myGroceryList = ['chips', 'pizza', 'hotpockets', 'MtnDew', 'corndogs']; // Do not edit the code above. Here we're going to…
1
vote
2 answers

This condition returns a boolean when checking for a falsy, but it returns a string when checking for a truthy value. How can I get it to work?

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 && !values.lastName && !values.email; But this doesn't,…
Grateful
  • 9,685
  • 10
  • 45
  • 77
0
votes
2 answers

How to return a new array with all truthy values removed? (Javascript)

I have seen how to remove falsy values from an array but haven't found a solution for returning a new array with all truthy elements removed. I attempted to replace falsy values with truthy ones in my "solution" but the results are not leaving me…
la10nay
  • 35
  • 3
0
votes
2 answers

trouble with truthy/falsey

A quick intro, I am a total noob learning JS and feel that it's going well, however I am doing a simple exercise right now and I'm hung up on something. I have learned that: a falsey value is a value that is considered false when encountered in a…