Modified 5 years, 5 months ago. The eval() function executes this and creates the variable with the assigned values. Using document.write: document: When an HTML document is loaded into a web browser, it becomes a document object. In summary, this technique is taking advantage of a feature of how the language is compiled. is unlike the var keyword, which defines a variable globally, or locally to an entire function regardless of block scope. cache Compiled functions are cached, requires filename; filename Used by cache to key caches, and for includes; root Set project root for includes with an absolute path (e.g, /file.ejs). It has entries for each argument the function was called with, with the first entry's index at 0.. For example, if a function is passed 3 arguments, you can access them as follows: Here's What I'm looking for: Get the img src variable by onclick() from home.html & pass to & document.write() to img.html using a location.href = '/image'; in my function() Thanks in advance. Any changes that you make to the arguments inside the function do not reflect the passing variables outside of the function. Example: { [variableName] : someValue } Starting with ECMAScript 2015, the object initializer syntax also supports computed property names. The values of these PHP string variables have to be transferred into javascript variables for further processing by javascript (or exposing these values in HTML directly) The problem: it is not safe to PHP-echo such variables into HTML (javascript) directly, because some of characters possily contained in them cause malfunction of the HTML. Inside eval(), we pass a string in which variable valuei is declared and assigned a value of i for each iteration.