I'm a very beginner in javascript. I'm declaring the string variable 'hello' based on the if condition. I want to print the variable 'hello' outside the if/else loop, how can I make this work?
var test = 4;
if (test > 3) {
let hello = "hello world";
}
else {
let hello = "hello gold";
}
console.log(hello);
I don't want this way
var test = 4;
if (test > 3) {
let hello = "hello world";
console.log(hello);
}
else {
let hello = "hello gold";
console.log(hello);
}