When we write code in modern JavaScript, we need to put the so-called strict mode in the first line. This mode forces the browser to use all modern language features.
You should put the command "use strict"
in the first line of the script to invoke strict mode.
Let's rewrite our code in strict mode:
"use strict";
alert('text!');
For simplicity, I will not point out that the code works in strict mode in the future (but it is assumed that it takes place, and you always enable it).
Invoke strict mode in your script.