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

  • SEARCH
  • Home
  • 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 7590427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:23:54+00:00 2026-05-30T20:23:54+00:00

I happened to know the following code Here is the code, and very simple:

  • 0

I happened to know the following code

Here is the code, and very simple:

var test = 0 || -1 ;
console.log(test);

then the output in the console is -1

and somehow i am really new into the javascript,

all i think of is that the 0 stands for Boolean False in JS ,and so || operator seems to ignore the 0 and assign the value -1 to the variable

so am i right ?
i just want a confirm

  • 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-05-30T20:23:55+00:00Added an answer on May 30, 2026 at 8:23 pm
    • || — expr1 || expr2 (Logical OR)

      Returns expr1 if it can be converted to true; otherwise, returns expr2. Thus, when used with Boolean values, || returns true if either operand is true; if both are false, returns false..

    • && — expr1 && expr2 (Logical AND)

      Returns expr1 if it can be converted to false; otherwise, returns expr2. Thus, when used with Boolean values, && returns true if both operands are true; otherwise, returns false.

    All values in Javascript are either “truthy” or “falsy”.
    The following values are equivalent to false in conditional statements:

    • false
    • null
    • undefined
    • The empty string "" (\ '')
    • The number 0
    • The number NaN

    All other values are equivalent to true.


    So… var test = 0 || -1 ; returns -1.

    If it was var test = 0 || false || undefined || "" || 2 || -1 it would return 2


    Logical operator on MDN

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

Sidebar

Related Questions

Let's look at the following piece of code which I unintentionally wrote: void test
Consider the following code: <html> <head></head> <body> <div id='test' class='blah'> <a href='http://somesite.com/' id='someLink'>click!</a> </div>
I don't know how it happened, but for about a week now Visual Studio
The following code compiles with G++ 4.6.1, but not with Visual Studio 2008 return
The following code is for authenticating to a windows AD server using Java+Kerberos and
here is my code: my task from celery.decorators import task @task() def add(x, y):
I had the following lines of C++ code in my program CFileDialog dialog(true); CString
In the computer that doesn't work it throws me the following error then I
I wanted a TextBox with just digits as entry. So i wrote following code
I was following the guide here: http://www.sqlalchemy.org/docs/orm/examples.html?highlight=versioning#versioned-objects and have come across an issue. I

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.