Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8765773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:22:18+00:00 2026-06-13T16:22:18+00:00

Hello fellow JS junkies. Can someone please explain to me the difference between the

  • 0

Hello fellow JS junkies. Can someone please explain to me the difference between the following ways of evaluating truthiness of variables?

var q1Var1 = "hello",
        q1Var2 = 0,
        q1Var3 = true,
        q1Var4 = "false",
        q1Var5 = -1,
        q1Var6 = undefined,
        q1Var7 = null,
        q1Var8;

// What is the difference between this block of code:

console.log( !q1Var1 );
console.log( !q1Var2 );
console.log( !q1Var3 );
console.log( !q1Var4 );
console.log( !q1Var5 );
console.log( !q1Var6 );
console.log( !q1Var7 );
console.log( !q1Var8 );

// and this block?

if( q1Var1 === true ){ console.log( "true" ) } else { console.log( "false" ) };
if( q1Var2 === true ){ console.log( "true" ) } else { console.log( "false" ) };
if( q1Var3 === true ){ console.log( "true" ) } else { console.log( "false" ) };
if( q1Var4 === true ){ console.log( "true" ) } else { console.log( "false" ) };
if( q1Var5 === true ){ console.log( "true" ) } else { console.log( "false" ) };
if( q1Var6 === true ){ console.log( "true" ) } else { console.log( "false" ) };
if( q1Var7 === true ){ console.log( "true" ) } else { console.log( "false" ) };
if( q1Var8 === true ){ console.log( "true" ) } else { console.log( "false" ) };

I was expecting to find that the second block would just be an inverse of the first (in other words, the values would just switch), however, it looks like only the variable set to nonstring “true” actually returns true. Why is this? What is the fundamental difference between the two evaluations:

!q1Var1

vs.

true === q1Var1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:22:20+00:00Added an answer on June 13, 2026 at 4:22 pm

    This illustrates the notion of “falsy” values in JavaScript. For instance, undefined becomes the same as false in a boolean context (such as an if condition). However, undefined === false is not true. The following are all “falsy” values:

    • false
    • undefined
    • the empty string
    • the number 0
    • null
    • NaN

    The === operator means “strictly equal” (see here, for instance); it suppresses automatic type conversions.

    Type conversion rules for the == operator (from the second link above) are:

    If the two operands are not of the same type, JavaScript converts the operands then applies strict comparison. If either operand is a number or a boolean, the operands are converted to numbers if possible; else if either operand is a string, the other operand is converted to a string if possible. If both operands are objects, then JavaScript compares internal references which are equal when operands refer to the same object in memory.

    Strict comparison rules are:

    • Two strings are strictly equal when they have the same sequence of characters, same length, and same characters in corresponding positions
    • Two numbers are strictly equal when they are numerically equal (have the same number value). NaN is not equal to anything, including NaN. Positive and negative zeros are equal to one another
    • Two Boolean operands are strictly equal if both are true or both are false
    • Two objects are never equal for either strictly or abstract comparisons
    • An expression comparing Objects is only true if the operands reference the same Object
    • Null and Undefined Types are == (but not ===)

    Note in particular that !var is not the same as var == false (and certainly not the same as var === false if var is not a boolean value to begin with). Non-empty strings are “truthy” (!"..." is always false for any non-empty "..."), but non-empty strings that evaluate to 0 when converted to numbers (like "0") are == false.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello there fellow Stackers! I wonder if anybody could tell me what the following
Hello fellow programmers, I'm using nice URLs the first time and I can't quite
hello fellow programmers, I followed a tutorial at http://www.androidsnippets.com/encrypt-decrypt-between-android-and-php to send a String encrypted
Fellow JQuery hackers, hello :-) Suppose you have the following code: $('.links').click(function(){ //Do something
hello fellow :) i am having a trouble on how can i retry sending
hello fellow java developers. I'm having a bit of an issue here. I have
Hello fellow software developers. I want to distribute a C program which is scriptable
Hello fellow StackOverflowers. I'm have a brain fart right now, and I cannot seem
Hello fellow developer,i've getting problem to set the Timer method on ZK,default the method
Hello fellow Grails Developers! I was wondering if you could help me with what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.