Javascript () Operator Invokes the Function
During the call of the function the code of the function gets executed. the call to the function can be made by the name of the function followed by the parentheses ().
example:
func(1,2);
This parentheses works as an operator to invoke the function to pass the values to the function. Also indicates to execute the statements of the function body. A function call without parentheses () always return the function definition.
This example to show a function call using () operator which performs an addition.
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
function add(a, b) {
return a + b;
}
document.getElementById("demo").innerHTML = add(4, 3);
</script>
</body>
</html>
Output:
7
This example to show a function call without using () operator.
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
function add(a, b) {
return a + b;
}
document.getElementById("demo").innerHTML = add;
</script>
</body>
</html>
Output:
function add(a, b) { return a + b; }
0 Comment(s)