Linked Questions

141 questions linked to/from Detecting an undefined object property
3104 votes
16 answers
3.8m views

What is the most appropriate way to test if a variable is undefined in JavaScript? I've seen several possible ways: if (window.myVariable) Or if (typeof(myVariable) != "undefined") Or if (...
90 votes
3 answers
135k views

Possible Duplicate: Detecting an undefined object property in JavaScript From the below JavaScript sample, try { if(jsVar) { proceed(); } } catch(e) { alert(e); } this jsVar is ...
Madhu's user avatar
  • 5,786
44 votes
4 answers
159k views

I've got a function that takes 3 parameters. The problem I have is one of the parameters is a property of a sometimes undefined value of an Object (i.e. it takes in thing.foo.bar, and sometimes thing....
Connor's user avatar
  • 4,188
43 votes
2 answers
227k views

Possible Duplicate: Detecting an undefined object property in JavaScript How to determine if variable is 'undefined' or 'null' Is there a standard function to check for null, ...
pmfl's user avatar
  • 2,109
16 votes
2 answers
50k views

I would like to check to see if a particular attribute of a DOM element is undefined - how do I do that? I tried something like this: if (marcamillion == undefined) { console.log("Marcamillion ...
marcamillion's user avatar
  • 33.9k
6 votes
6 answers
5k views

My question is about preventing an "variable is undefined" error more effiencitly. e.g If I use the following code: if (array[index] != undefined) { if (array[index].id == 1) { // code } ...
user avatar
2 votes
1 answer
13k views

I had been checking for undefined values myself like: if(variable !== 'undefined') then I came across the following code: if(typeof variable1 !== 'undefined' || typeof variable2 !== 'undefined') I ...
9 votes
4 answers
745 views

From the book Maintainable JavaScript it mentioned : // Bad: Testing to see if an argument was passed function doSomething(arg1, arg2, arg3, arg4){ if (arg4 != null){ doSomethingElse(); } } but ...
vancewang's user avatar
  • 5,470
3 votes
5 answers
430 views

Possible Duplicate: Detecting an undefined object property in JavaScript Would it be like this? if(variable == undefined) { or would it be like this? if(variable == "undefined") {
0 votes
1 answer
11k views

Why is it going into his if when the check is if its not undefined if (this.table !== undefined || this.table !== null) { this.table.destroy(); } Console error : Uncaught ...
1 vote
1 answer
6k views

runAnimation: function(){ var iframe = document.querySelector('.active iframe'); window.frames[iframe.id].contentWindow.runAnimation(); }, The above code prints the following error in Safari: ...
9 votes
1 answer
332 views

There's a syntax that Javascript adopted from C where you can perform a logical check, without checking anything: if (foo) { } What is this equivalent to? Is it: if (foo != null) { } if (foo !== ...
Ian Boyd's user avatar
  • 259k
-3 votes
1 answer
359 views

var a; typeof(a); //undefined typeof(c); //undefined if(c) {} //throw error How can I know that c doesn't exist without try catch. Update after marked duplicate: typeof initializedVariable and ...
vusan's user avatar
  • 5,357
0 votes
1 answer
295 views

Let's say you have the following function: var variable; function(variable); function function(variable) { alert ("variable equals " + variable); if (variable != 'undefined') { ~~~...
0 votes
2 answers
315 views

I'm using a callback to create an object, which I'd like to parse. I'm able to parse the object when the name/value pair I've specified exists, but unable to identify when the name/value pair in my ...

15 30 50 per page
1
2 3 4 5
...
10