How to determine if variable is 'undefined' or 'null'? How do I determine if variable is undefined or null? My code is as follows: var EmpName = $("div#esd-names div#name").attr('class'); if(EmpName == 'undefined'){ //DO SOMETHING }; <div id="esd-names"> <div id="name"></div> </div> But if I do this, the JavaScript interpreter halts execution. Answer: You can do this: if (variable == null){ // your code here. } Check MDN for details on equality tests in JS. null == undefined is true, but null === undefinedis false. Thus the code above, as is, will catch
undefined
PHP: “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” I am running a PHP script, and keep getting errors like: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php on line 10 Notice: Undefined index: my_index C:\wamp\www\mypath\index.php on line 11 Line 10 and 11 looks like this: echo "My variable value is: " . $my_variable_name; echo "My index value is: " . $my_array["my_index"]; What do these errors mean? Why do they appear all of a sudden? I used to use