[jshint] "document.write can be a form of eval."
I saw JSHint and JSLint recommended to catch syntax errors, but I don't understand why they don't like this code:
Here's the report:
var s = "hello world!"; // A string
var word = s.substring(s.indexOf(" ") + 1, s.length); // Use string properties
Why is document.write() wrong, and what else should I use to simply output something to the browser?
Line 3: document.write(word);
document.write can be a form of eval.
You can google for why it is wrong - much has been written on the subject. The simplest way to output is by giving an element like a div an ID and doing document.getElementById("theid").innerHTML=word;
If you are using a modern browser you can also log to the console by doing console.log(word);
Further along the line you may want to explore createElement(), but that is more complicated and results are very ambiguous as to whether it is better.
Thanks for the infos. I'll use getElementById().
As for not using document.write(), I found this: "Why is document.write considered a 'bad practice'?"
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)