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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:11:10+00:00 2026-06-14T08:11:10+00:00

I have this code: function getSessionGUID() { return (S4()+S4()); } function S4() { return

  • 0

I have this code:

function getSessionGUID() {
   return (S4()+S4());
}

function S4() {
   return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}

It clearly returns a string, but if you run it a bunch of times, you can notice that it sometimes returns infinity.

for (var i = 0; i < 100000; i++){ if(getSessionGUID() == Infinity) console.log("INFINITY"); }
871 x INFINITY

I then noticed that if you remove the |0, it solves the problem:

function S4() {
   return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}

Results:

for (var i = 0; i < 100000; i++){ if(getSessionGUID() == Infinity) console.log("INFINITY"); }
undefined

Why does this happen? In both cases the value is changed into a string.

  • 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-14T08:11:11+00:00Added an answer on June 14, 2026 at 8:11 am

    This test reveals the answer:

    for (var i = 0; i < 100000; i++){
      var x=getSessionGUID();
      if(x == Infinity) console.log(x); }
    }
    

    It logs values like 61e93284 or 1413e390

    These values are valid numbers and they are way too big for the Number type, so they get cast as Infinity when interpreted as a number.

    If you replace == with === in the test, no conversion occurs and nothing is logged. The conversion is caused by the == operator.

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

Sidebar

Related Questions

i have this code $(function() { $('#ans_vote a span').click(function(){alert('working');return false;});}); and this html <div
I have this code function test(){}; test.prototype.testMethod = function(){return 1;} var t = new
I have this PHP code: function ShowFileExtension($filepath) { preg_match('/[^?]*/', $filepath, $matches); $string = $matches[0];
I have this code: getThirdPartyID : function () { return FB.api(/me?fields=third_party_id, function (userData) {
I have this code: function Keyboard() { this.log = $('#log')[0]; this.pressedKeys = []; this.bindUpKeys
I have this code: function submitTwice(f){ f.action = 'http://mydomain.com/threevideopage.php'; f.target='name'; f.submit(); } I left
I have this code: _trackit: function(){ for(var key in this.items.sublinks){ switch(key){ case 'shoes': for(var
I have got this code: function init(){ if (typeof window.jQuery !== 'function') { var
I have this code snippet: $(function() { $('.toolbar [id^=button]').on('click', function () { $(this) .css('background-color',
I have this code in a function $_SESSION['id'] = $id; $_SESSION['pineapple'] = $hashbrown; $_SESSION['username']

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.