You're currently trying to use calculate
before you've defined it. According to the rules on variable hoisting:
Variables declared with let
and const
are also hoisted, but unlike for var
the variables are not initialized with a default value of undefined
. Until the line in which they are initialized is executed, any code that accesses these variables will throw an exception.
So you are seeing that exception.
First define calculate
. Then you can use calculate
:
const strValue = prompt("Please! enter the value ");
const calculate = s => {
//.. whatever your function definition is
};
const abc = calculate(strValue);
document.getElementById("demo").innerHTML = abc;
(As an aside, I've also added const
declarations for your other variables. If they are already declared elsewhere, don't re-declare them here of course. But for completeness of this example I'm simply demonstrating that variables should have declarations so as to not pollute the window
object with properties that should have been declared variables.)