0

I am a very beginning in javascript and these are my first lines in it I am following a tutorial and I believe I did the same but even though I have this flag error, I saw the same questions but still don’t understand the cause of the problem enter image description here my code

alert("hello");

the error

index.js:1 Uncaught TypeError: alert is not a function
at index.js:1
(anonymous) @   index.js:1

2 Answers2

0

The alert() function is a JavaScript function in Web Browsers. You can not use it in a plain .js file that you execute locally; you have to run it in a web browser. FInd more information here and here.

  • They are running it in browser as [a snippet](https://developer.chrome.com/docs/devtools/javascript/snippets/) – adiga May 14 '21 at 11:10
  • Sorry mate, didn't see that because of the colourscheme. I thus assumed this was an IDE and didn't notice the other Developer's Console tabs. The snippet works for me too, so I am not sure what is happening. Maybe OP is experiencing an issue with the specific version of Chrome having a bug? – Casey Kuilman May 14 '21 at 11:16
-1

There is one more possible reason: alert might be blocked by browser extensions (like ad blockers). Check window.alert in your console. If it's not a function, that might be the case.

mrother
  • 36
  • 6