Error on using alert in Javascript (Property 'alert' of object is not a function)

Idan Shechter picture Idan Shechter · Jul 4, 2012 · Viewed 23.5k times · Source

I am just trying to use alert and put a string variable inside the alert and get an error:

Uncaught TypeError: Property 'alert' of object [Object Window] is not a function

My code is:

var shortenurl = msg.d;
alert(shortenurl);

I've checked the value and it has a string inside, not an object.

Answer

Chris Laplante picture Chris Laplante · Jul 4, 2012

Somewhere in your code you overrode alert. Check for var alert = ... or some other kind of declaration like that. Also check for window.alert declarations.