classic mistake! you’re redeclaring fetchInfo inside executeRequest, which shadows the original function. js hoists the const declaration but can’t access it before initialization - that’s why you’re getting the error. just rename the variable and you’ll be good to go.
You’ve encountered a variable name collision in your executeRequest function. By declaring a variable with the same name as the outer fetchInfo function, you are shadowing it. When you write const fetchInfo = await fetchInfo(…), JavaScript recognizes the const fetchInfo declaration first, leading to that reference error since you’re using it before it’s initialized.
An easy fix is to rename the variable within executeRequest:
I’ve faced this issue multiple times when refactoring. The combination of the temporal dead zone with const and variable shadowing often results in confusing error messages. To avoid this, steer clear of using the same name for variables and functions in overlapping scopes.
This happens because of variable shadowing and JavaScript’s temporal dead zone. You’re declaring a new fetchInfo variable with const inside executeRequest, but trying to call the outer fetchInfo function on the same line before the variable gets initialized. JavaScript sees the const declaration first and creates a binding for fetchInfo in that scope, which shadows the outer function. Since you can’t access const variables before they’re declared, you get the reference error. I hit this exact issue last month when I reused a function name as a variable. Easy fix - just use a different variable name: const executeRequest = async() => { const data = await fetchInfo(WEATHER_ENDPOINT, API_HOST); console.log(data); } This avoids the naming conflict and your code should work fine.