Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSLint "document.write can be a form of eval" - How is this so?

I've come across this message in JSLint...

document.write can be a form of eval.

and was wondering exactly how so?

The JSLint instructions page states:

The eval function...provide access to the JavaScript compiler. This is sometimes necessary, but in most cases it indicates the presence of extremely bad coding....

So, how does document.write "provide access to the JavaScript compiler" then?

Thanks

like image 717
James Wiseman Avatar asked Mar 30 '11 15:03

James Wiseman


People also ask

What does document write can be a form of eval mean?

write can be a form of eval means is: the syntax document. write relates to/ uses the eval function, an inbuilt js function.

What is the use of Document write () method in Javascript?

The document. write() method writes a string of text to a document stream opened by document.

What is the point of eval?

Answer: eval is a built-in- function used in python, eval function parses the expression argument and evaluates it as a python expression. In simple words, the eval function evaluates the “String” like a python expression and returns the result as an integer.


1 Answers

What does your browser do with this?

document.write('<script type="text/javascript">window.alert("evaled " + (1 + 2))</script>');
like image 79
Ben Voigt Avatar answered Oct 25 '22 09:10

Ben Voigt