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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:46:44+00:00 2026-06-12T19:46:44+00:00

I found the following code in a JS project: var a = new Array();

  • 0

I found the following code in a JS project:

var a = new Array();
a[0] = 0;
for (var b = 0; b < 10; b++) {
  a[0] |= b; 
}

What does the |= do in the body of the for loop?

The code example is dubious, but has been presented here by V8 for an example of improved performance.

Updated Example

The above example is equivalent to var a = [15]; for most intents and purposes. A more realistic example for the |= operator would be to set up binary flags in a single variable, for example on a permission object:

//Set up permission masks
var PERMISSION_1_MASK = parseInt('0001',2);
var PERMISSION_2_MASK = parseInt('0010',2);
..

//Set up permissions
userPermissions = 0;
userPermissions |= hasPermissionOne && PERMISSION_1_MASK;
userPermissions |= hasPermissionTwo && PERMISSION_2_MASK;
..

//Use permissions
if(userPermissions & PERMISSION_1_MASK){
    ..//Do stuff only allowed by permission 1
}
  • 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-12T19:46:45+00:00Added an answer on June 12, 2026 at 7:46 pm
    a[0] |= b
    

    is basically

    a[0] = a[0] | b
    

    “|” is an or bitwise operator

    Update
    When a[0] is assigned 0, a[0] in binary is 0000. In the loop,

    1. b = 0

      a[0] = 0 (base 10) = 0000 (base 2)
      b    = 0 (base 10) = 0000 (base 2)
                         ---------------
      a[0] | b           = 0000 (base 2) = 0 (base 10)
      
    2. b = 1

      a[0] = 0 (base 10) = 0000 (base 2)
      b    = 1 (base 10) = 0001 (base 2)
                         ---------------
      a[0] | b           = 0001 (base 2) = 1 (base 10)
      
    3. b = 2

      a[0] = 1 (base 10) = 0001 (base 2)
      b    = 2 (base 10) = 0010 (base 2)
                         ---------------
      a[0] | b           = 0011 (base 2) = 3 (base 10)
      
    4. b = 3

      a[0] = 3 (base 10) = 0011 (base 2)
      b    = 3 (base 10) = 0011 (base 2)
                         ---------------
      a[0] | b           = 0011 (base 2) = 3 (base 10)
      
    5. b = 4

      a[0] = 3 (base 10) = 0011 (base 2)
      b    = 4 (base 10) = 0100 (base 2)
                         ---------------
      a[0] | b           = 0111 (base 2) = 7 (base 10)
      
    6. b = 5

      a[0] = 7 (base 10) = 0111 (base 2)
      b    = 5 (base 10) = 0101 (base 2)
                         ---------------
      a[0] | b           = 0111 (base 2) = 7 (base 10)
      
    7. b = 6

      a[0] = 7 (base 10) = 0111 (base 2)
      b    = 6 (base 10) = 0110 (base 2)
                         ---------------
      a[0] | b           = 0111 (base 2) = 7 (base 10)
      
    8. b = 7

      a[0] = 7 (base 10) = 0111 (base 2)
      b    = 7 (base 10) = 0111 (base 2)
                         ---------------
      a[0] | b           = 0111 (base 2) = 7 (base 10)
      
    9. b = 8

      a[0] = 7 (base 10) = 0111 (base 2)
      b    = 8 (base 10) = 1000 (base 2)
                         ---------------
      a[0] | b           = 1111 (base 2) = 15 (base 10)
      
    10. b = 9

      a[0] = 15 (base 10) = 1111 (base 2)
      b    =  9 (base 10) = 1001 (base 2)
                          ---------------
      a[0] | b            = 1111 (base 2) = 15 (base 10)
      

    At the end of the loop the value of a[0] is 15

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

Sidebar

Related Questions

I found the following code in my team's project: Public Shared Function isRemoteDisconnectMessage(ByRef m
I found the following code somewhere, but I am not understanding the code properly.
Hi I found the following code from this page JQuery UI DatePicker using 2
I've found the following code: https://github.com/roddi/ValidateStoreReceipt/blob/master/validatereceipt.m which loads the root certificate ('Apple Root CA')
At a website , I found the following code to make a jQuery plugin:
Somewhere here on Stack Overflow, I had found the following code some day which
The following code produces no suitable constructor found error. I am unable to figure
The following code can be found in the NHibernate.Id.GuidCombGenerator class. The algorithm creates sequential
I found the following piece of code from the adw launcher: Object service =
I am trying to run the following code that I found marked as correct

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.