1

I take 'Uncaught ReferenceError: Cannot access 'calculate' before initialization at hesapmakinesi3.html:10' I can't see where error I don't know any do this

  $: strValue =prompt("Please! enter the value ");
  $: abc=calculate(strValue);
  document.getElementById("demo").innerHTML = abc;
  const calculate = s => {

2 Answers2

0

Without seeing much, it looks like you're trying to call a method calculate before it's actually initialized.

You want to first initialize it:

const calculate = s => {};

and then use it after it's being declared.

Zer0
  • 1,002
  • 1
  • 19
  • 40
0

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.)

David
  • 208,112
  • 36
  • 198
  • 279