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 843385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:07:04+00:00 2026-05-15T06:07:04+00:00

I saw this construction in order to get the browser viewport width: function ()

  • 0

I saw this construction in order to get the browser viewport width:

function () { return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; }

I understand the browser quirks involved. What I don’t understand is why || returns the value. So I tried this alert(undefined || 0 || 3); and sure enough, it alerts 3. I find this bizarre, because I expect true or false. Could anyone explain what’s going on?

  • 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-15T06:07:05+00:00Added an answer on May 15, 2026 at 6:07 am

    Take a look at the ECMAScript standards section 11.11 Binary Logical Operators

    The production LogicalORExpression :
    LogicalORExpression ||
    LogicalANDExpression is evaluated as
    follows:

    1.Evaluate LogicalORExpression.

    2.Call GetValue(Result(1)).

    3.Call ToBoolean(Result(2)).

    4.If Result(3) is true, return Result(2).

    5.Evaluate LogicalANDExpression.

    6.Call GetValue(Result(5)).

    7.Return Result(6).

    So it evaluates the boolean conversion of each operand, but returns the actual value of the operand.

    If you want to know how Javascript converts values to a boolean, see section 9.2 ToBoolean

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

Sidebar

Ask A Question

Stats

  • Questions 495k
  • Answers 495k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use Delegate.CreateDelegate(Type, MethodInfo): MethodInfo method = s.Type.GetMethod("FileAdded"); var handler =… May 16, 2026 at 11:19 am
  • Editorial Team
    Editorial Team added an answer The .pl extension needs to be associated with the Perl… May 16, 2026 at 11:19 am
  • Editorial Team
    Editorial Team added an answer Case insensitive queries by default only work with ASCII characters… May 16, 2026 at 11:18 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

My JavaScript is pretty nominal, so when I saw this construction, I was kind
I am a PHP beginner and saw on the forum this PHP expression: My
I recently saw this constructor in a class: public MyClass(){ } There were no
I saw this in someone's code and thought wow, that's an elegant way to
I saw this question Inject into private, package or public field or provide a
I saw this kind of code at work: class FooPlugin : IPlugin // IPlugin
I just saw this term on a job I was applying for and I'm
I know this may seem like a math question but i just saw this
So I was doing a refresher on Ruby and I saw this guy's blog
How can i change system culture that affects all pages(programmatically)? i saw this thread.

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.