简体   繁体   中英

Javascript function return result of a function differently in chrome for different instances

First i executed the below script in chrome console

 var x = 1; if (function f(){}) { x += typeof f; } x; 

I got '1undefined' as result.

Then i executed function f(){} in console and again executed the above script,then i got the result '1function'. Now i opened another instance of chrome browser and again run the above script i am getting '1object'.

My question is why i am getting different result.

step1:- Run the above code snippet in chrome console. Result is 1undefined

step 2:-Run function f(){} in chrome console.Result is 1function

step 3:-open another instance of chrome and run the above snippet again.Result is 1object

below that 1object ..i have this text 'Application Cache Checking event'

When you open another tab of chrome, it by defaults open Google home page. If you execute the script there from console even for the first time, it will print 1object. As there is a javascript file on that page that define a variable F as object. You can check it here https://www.google.co.in/_/chrome/newtab?espv=2&ie=UTF-8

As most sites minify js files, the variable are named A,B.....

Its not magic :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM