/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Null value problem

Hello everyone! =)

I’m strugling with this for hours, please help!!!

I’m building javascript application that uses the web service to fetch x and y coordinates, and then draw points on the map. Should be very simple. Part of my code looks like this:


261 var xPos = data.LastState[0].GeoX.toString();
262 var yPos = data.LastState[0].GeoY.toString();
263 var pt = { x: xPos, y: yPos };

I’m using IE8 for testing. I’m constatntly getting the same error: Line 261 – data.LastState.0.GeoX is null or not an object. Fine, that’s quite possible to happen, the problem is when i try to filter those null results out. I tried the following:

if (data.LastState[0].GeoX == null)…
if (data.LastState[0] == null)…
if (data.LastState == null)…
if (data == null)…
if (data.LastState[0].GeoX == undefined)…
if (data.LastState[0] == undefined)…
if (data.LastState == undefined)…
if (data == undefined)…

Every single one of these conditional statements evaluates to false, yet the “data.LastState.0.GeoX is null…” error raises.

Moreover, i did this:
alert(data.LastState[0].GeoX) – this returns 17.4345430 or something similar, not null or undefined or empty alert or anything.

How is that possible???? How can this happen:

260: alert(data.LastState[0].GeoX); //17.4345430
261: xPos = data.LastState[0].GeoX; //data.LastState.0.GeoX is null or not an object!!!

Please help!!!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@knciskoauthorApr 18.2011 — If anyone's interested, checking if LastState.length > 0 did the trick! =)
×

Success!

Help @kncisko spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...