I know this might have a really simple answer but I can't seem to figure it out.
I need to define the contents of a variable depending on the value of a parameter coming to a function.
The issue is that when I set my values inside an if I get ReferenceError: newval is not defined
Below is a simplified version of the code which runs the error:
const myMessage = (recipientId, msg, miller) => {
const tip = 1;
if (tip===1)
{
console.log("in here");
const newval = "some value";
}
console.log("executes this");
const send = newval;
When I check the console I get the in here before the execute this message. That is why I am not sure why send doesn't know what newval is.
Any tip in the right direction will be appreciated, Thanks
constandletare block scoped, they are not hoisted likevar