If you declare (and initialize) a variable within an if-else statement, then that variable’s value will only exist within that if-else statement. However if you want to initialize (i.e. assign a value to) the variable within the if-else statement, but want to make the variable accessible outside the if-else scope, then you need to first declare the variable, in the highest most scope where you want to make the variable accessible, and then initialize it within the scope, here’s an example: