I'm kind of curious why this doesn't work
JavaScript:
function evaluate(){
console.log(42);
}
HTML:
<a onclick="evaluate()">Click Me!</a>
Is evaluate a reserved keyword somewhere on the html side?
Calling eval() will be slower than using alternatives, because it has to call JavaScript interpreter, which will convert evaluated code to the machine language. That means if you run the code more than once, the browser will have to interpret the same code again, which is highly inefficient.
eval() is a function property of the global object. The argument of the eval() function is a string. It will evaluate the source string as a script body, which means both statements and expressions are allowed. It returns the completion value of the code.
Calling a function using external JavaScript file Js) extension. Once the JavaScript file is created, we need to create a simple HTML document. To include our JavaScript file in the HTML document, we have to use the script tag <script type = "text/javascript" src = "function.
Use the keyword function followed by the name of the function. After the function name, open and close parentheses. After parenthesis, open and close curly braces. Within curly braces, write your lines of code.
document.evaluate
is needed for parsing XMLs, see the reference in the MDN here.
Evaluate is not a reserved word in JavaScript, document.evaluate
is used to evaluate XPath expressions.
You could still name your function evaluate
if you used a less obtrusive method of attaching your event handler:
var evaluate = function (){
console.log(42);
}
document.addEventListener('click', evaluate, false);
Example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With