0

Variable scope

Why my code says (y) is not defined? https://code.sololearn.com/W3oU6AAQ7SXf/?ref=app

27th May 2020, 9:43 PM
JS LOVER
JS LOVER - avatar
5 odpowiedzi
+ 4
JS LOVER You have defined variable inside if block using let keyword so you can't access outside the block. But when you use var keyword then you can access
27th May 2020, 10:24 PM
A͢J
A͢J - avatar
+ 5
JS LOVER let variables are block-scoped. It's well explained here: https://www.sololearn.com/learn/JavaScript/2969/ Keep learning the JS tutorial. You are going to reach that lesson soon. Var vs Let: https://www.sololearn.com/post/39014/?ref=app
27th May 2020, 10:22 PM
Kevin ★
+ 1
coffeeunderrun sorry! I was facing a bad network connection
27th May 2020, 9:55 PM
JS LOVER
JS LOVER - avatar
+ 1
Thank you guys
27th May 2020, 11:53 PM
JS LOVER
JS LOVER - avatar