ReferenceError: variable is not defined

前端 未结 3 1224
南旧
南旧 2020-11-30 05:51

I met this issue sometimes but still don\'t know what causes it.

I have this script in the page:

$(function(){
    var value = \"10\";
});

3条回答
  •  猫巷女王i
    2020-11-30 06:22

    Got the error (in the function init) with the following code ;

    "use strict" ;
    
    var hdr ;
    
    function init(){ // called on load
        hdr = document.getElementById("hdr");
    }
    

    ... while using the stock browser on a Samsung galaxy Fame ( crap phone which makes it a good tester ) - userAgent ; Mozilla/5.0 (Linux; U; Android 4.1.2; en-gb; GT-S6810P Build/JZO54K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30

    The same code works everywhere else I tried including the stock browser on an older HTC phone - userAgent ; Mozilla/5.0 (Linux; U; Android 2.3.5; en-gb; HTC_WildfireS_A510e Build/GRJ90) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

    The fix for this was to change

    var hdr ;
    

    to

    var hdr = null ;
    

提交回复
热议问题