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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:55:19+00:00 2026-05-25T06:55:19+00:00

var f = 5, d; while (f === 5) d = 2; alert(d); Why

  • 0
var f = 5, d;

while (f === 5) d = 2;

alert(d);

Why does this freeze my page. I thought only when the page is doing a document.write, alert, or console.log inside a while loop (without a incremented value with a limit) it will freeze the page, but not with variables… Do I still have to have a var i = 0; while (i < 5 &&... just to get this to work?

EDIT: I found this in the source-code of google. This while loop doesn’t have a number limit but it doesn’t freeze the page:

while (a && !(a.getAttribute && (b = a.getAttribute("eid")))) a = a.parentNode;
  • 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-25T06:55:20+00:00Added an answer on May 25, 2026 at 6:55 am

    The Google loop you edited into your question is testing the value of a in the while condition and it is modifying the value of a inside the loop, so the loop will terminate when a (or one of the other conditions based on a) is no longer truthy.

    while (a && !(a.getAttribute && (b = a.getAttribute("eid")))) a = a.parentNode;
    

    For a loop to terminate, some value that you are testing in the loop condition must change to a falsey value sometime during the iteration of the loop. It doesn’t have to be numbers, it can be other things that have a truthy or falsey notion to them.

    In that Google loop, there are two conditions that can make it terminate:

    1. a is no longer truthy (null, undefined, 0, false, etc…).
    2. a.getAttribute(“eid”) exists.

    So, basically this is going up the parent chain looking for the first parent that has getAttribute(“eid”). It stops either when it runs out of parents to check or it finds a parent with that attribute.

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

Sidebar

Related Questions

I have this code here: var infiltrationResult; while(thisOption) { var trNode = document.createElement('tr'); var
While using this code to serialize an object: public object Clone() { var serializer
$(.sectionHeader).click(function() { var row = $(this).parent(); while (row.next().length != 0) { row = row.next();
i have this js code : var str = javascript:__doPostBack('ctl00$M$List$_rli2$ctl06',''); alert (str); var str
var x = window.Something; alert(window.x) when i try this code in jsfiddle http://jsfiddle.net/XJEGU/ ,
this.fillSelectBox = function (flowCounterObj) { while (this.selectBox.hasChildNodes()) { this.selectBox.removeChild(this.selectBox.firstChild); } var line = 0;
While reading a book about JavaScript I stumbled across an example: var names =
I have the following code in specman: var x := some.very.long.path.to.a.variable.in.another.struct; while (x ==
i'm using the following code to submit a form: function submitfilter(){ alert(in here); var
while review a javascript coding, i saw that var detailInf = { hTitle:Results, hMark:98

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.