简体   繁体   中英

How can I stop an alert from being a function?

When I tried to run my code:

var intro = function () {
  alert('Welcome');
  alert('Hello!');
};

intro();

In the browser console, it gave me the error that alert was not a function. Along with all the other alerts in my code. How could I change these alerts and all of my other alerts so that the console doesn't think they're functions?

I'm sorry if this is a bad question, I am a beginner to JS.

Edit: the reason the alerts are in the function is because I thought that that could solve the problem and it didn't.

One and only way to reproduce this case for me is:

 alert = "cv634v5ctwhatever"; var intro = function () { alert('Welcome'); alert('Hello!'); }; intro(); 

Try to figure out when you or some others assign a value to the alert in code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM