Cannot access variable before initialization

Hi! I’m trying to make a calculator from scratch and I’m more or less getting the calculator built right, just that I’m having an issue with my variables.

My javascript is here, my error is in the part where I commented out “let currentNumber = result;” for the plus/minus/times/divide operation, it’s supposed to work so that my calculator functions right, but the console shows “Uncaught ReferenceError: Cannot access ‘currentNumber’ before initialization” - though I thought it was strange, because currentNumber has already been defined. Appreciate any tips to point me in the right direction!

let currentNumber = '';
let previousNumber = '';

// jquery for document onload
$(()=> {

// for keying in numbers
const $currentNum = $(".number").on("click", (event) => {
    currentNumber = currentNumber.concat($(event.currentTarget).text())
    $('.display')[0].innerText = currentNumber
    console.log(currentNumber)
  });

// for keying in operations
const $operation = $(".operation").on("click", (event) => {
    console.log($(event.currentTarget).attr('class'))
    previousNumber = currentNumber.concat($(event.currentTarget).text());
    currentNumber = '';
    console.log(previousNumber)
  });

// for calculating result
const $equal = $(".equal").on("click", (event) => {
    // if currentNum has +, means add
    if (previousNumber.includes("+")){
        let result = parseFloat(previousNumber.replace('+','')) + parseFloat(currentNumber)
        console.log(parseFloat(previousNumber.replace('+','')) + parseFloat(currentNumber));
        $('.display')[0].innerText = result;
        // let currentNumber = result;
    }

    // if currentNum has -, means minus
    else if (previousNumber.includes("-")){
        let result = parseFloat(previousNumber.replace('-','')) - parseFloat(currentNumber)
        console.log(parseFloat(previousNumber.replace('-','')) - parseFloat(currentNumber));
        $('.display')[0].innerText = result;
        // let currentNumber = result;
    }

    // if currentNum has *, means multiply
    else if (previousNumber.includes("*")){
        let result = parseFloat(previousNumber.replace('*','')) * parseFloat(currentNumber)
        console.log(parseFloat(previousNumber.replace('*','')) * parseFloat(currentNumber));
        $('.display')[0].innerText = result;
        // let currentNumber = result;
    }

    // if currentNum has ÷, means divide
    else if (previousNumber.includes("÷")){
        let result = parseFloat(previousNumber.replace('÷','')) / parseFloat(currentNumber)
        console.log(parseFloat(previousNumber.replace('÷','')) / parseFloat(currentNumber));
        $('.display')[0].innerText = result;
        // let currentNumber = result;
    }
    
  });

})

Here is my jsfiddle link to see how it functions: https://jsfiddle.net/09g8wstz/

Hey Zinc,

Remove the let from the commented out line and it will work fine.

Thank you, it did work but then I ran into another error saying that my concat function has an error…I’ll check it through again!