if val := getVal(); val < 10 { return val } else { return val + 1 } This is not possible in JS
if val := getVal(); val < 10 { return val } else { return val + 1 }
This is not possible in JS
What does it do?
Sorry, I should have explained it better. I'll update the post
the variable is scoped to the if statement. Thus, it is much more readable. might be that the getVal() function would be like this.
if
getVal()
func getVal() int{ // return any number return 0 }
compare to javascript
// given by the example. the `val` is mutable let val = getVal() if(val < 10){ return val } else{ return val + 1 }
in golang, after if block, variable val continues existing? Or it just exists in the if block?
val
val is no longer accessible after the if statement. the variable is scoped to the if block
Thanks
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
What does it do?
Sorry, I should have explained it better. I'll update the post
the variable is scoped to the
if
statement. Thus, it is much more readable. might be that thegetVal()
function would be like this.compare to javascript
in golang,
after
if
block, variableval
continues existing? Or it just exists in theif
block?val
is no longer accessible after theif
statement. the variable is scoped to theif
blockThanks