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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:08:31+00:00 2026-05-19T11:08:31+00:00

update: for( i in window)if(i==’onhashchange’)console.log(i, window[i]); //prints onchangechange undefined on browser where onhashchange event

  • 0

update:

for( i in window)if(i=='onhashchange')console.log(i, window[i]); //prints onchangechange undefined

on browser where onhashchange event is supported I have

'onhashchange' in window;  //returns true
window['onhashchange']; //returns false
window.onhashchange;  //returns false;

why does the former returns true and the rest returns false?

  • 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-19T11:08:32+00:00Added an answer on May 19, 2026 at 11:08 am

    I think with help of the first operation you just check if such an event is in window object, so it returns true. Two other tell you if such a handler is implemented, and there is no implementation yet you get false.
    Can you check the following:

    window.onhashchange = function() {}
    window['onhashchange'];
    

    yea, anyway it will return true now, because we have defined that variable… So most probably

    'onhashchange' in window;
    

    just checks if browser supports it

    window['onhashchange']; //returns false
    window.onhashchange;  //returns false;
    

    just checks if handler already implemented

    PS. Also you can be interesting in Javascript IN operator compatibility, here @Andy E wrote:

    You should err on the side of caution when using it to check event support. All implementations except Mozilla support “eventname” in element as a test for DOM events, Firefox will result in false here unless a handler is defined.

    UPDATE: to see difference between “x in window” and “window.x” (which is equal to window[‘x’]), take a look at the following script and its output:

    var foo = {};
    console.info( 'bar' in foo ); // false, because no such proeprty
    console.info( foo.bar ); // undefined, because no such property
    console.info( foo.bar ? 'true' : 'false' ); // 'false' because no such property
    
    foo = { bar: false };
    console.info( 'bar' in foo ); // true, because there is such property
    console.info( foo.bar ); // false, because this is value of bar property
    console.info( foo.bar ? 'true' : 'false' ); // 'false' because foo.bar is false
    
    foo = { bar: 1 }; 
    console.info( 'bar' in foo ); // true, because there is such a property
    console.info( foo.bar ); // 1, because this is value of bar proeprty
    console.info( foo.bar ? 'true' : 'false' ); // 'true', because foo.bar is 1 (which is not 0 which meant to be false)
    
    foo = { bar: 0 }; 
    console.info( 'bar' in foo ); // true, because there is such a property
    console.info( foo.bar ); // 0, because this is value of bar proeprty
    console.info( foo.bar ? 'true' : 'false' ); // 'false', because foo.bar is 0 (which meant to be false)
    

    UPDATE2: Detecting event support without browser sniffing – this article shows how to make event detection cross browser (because “event in window” does not work in Mozilla; this article also answers why it is so)

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

Sidebar

Related Questions

I write Python scripts with NppExec/Notepad++. How do I update my console window as
I have few questions, I want to show the alert window on my Update
I have two windows, a main window an a window to update the database,
I have a window with a telerik gridview in it and i update this
I call window.location.reload(false) in a javascript method to update the page. I have additional
How to change and update the title of the command prompt window from the
I'm trying to update an image in a parent window with clickable links in
Here's the problem html: <ul id="update-list"> <li class="update" onclick="window.location('some_url')"> <h2> some header </h2> <p>
A recent Windows Update or software installation seems to have broken my one week
how to intercept that the update of window to the windows driver level? ---windows

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.