let & var

Get help with Code for Teens
Post Reply
Audiferus
let & var

Post by Audiferus » Sat Jun 27, 2020 6:30 pm

So I'm working through your book with my nephew. When I learned coding (a looooooooong time ago), I would get an error when I used "let" to define the same thing. I started the book a few months ago, and did everything so that when I went through it with my nephew, I'd be good to go. Cue, Covid, so he has lots of free time and we finally got around to working through it together, me as his teacher, religiously reading the book, and him, on Google Meet, following along and doing the exercises.

So a few months ago, I still got an error when I used "let" to define something, now I don't.... now he doesn't ... in fact, we can define things without using let or var or const being in front of it. What gives? Is the undeclared definition a var? a const? let?

Any advice? I basically told him to keep good form, and declare only once, but I'm not sure if that's just me being a purist or if it will later affect stuff.

JeremyMoritz
Site Admin
Posts:20
Joined:Mon May 14, 2018 10:19 pm
Location:Kansas
Contact:

Re: let & var

Post by JeremyMoritz » Sat Mar 27, 2021 2:39 pm

Great question, Audiferus!

Go ahead and be a purist! declare with `let` the first time and then don't use `let` again if you reassign it. Chrome used to throw an error if you used `let` a 2nd time, but it's more forgiving now. Still, the correct practice is to use it only the first time.

`var` is the loosest of the three, which is why it is avoided my modern javascript developers. Best to understand it if you see it but try not to ever write it yourself.

Happy coding!
Jeremy Moritz
Author of Code for Teens
www.CodeForTeens.com

User avatar
Williamnen
Posts:8
Joined:Mon Nov 22, 2021 12:27 pm
Location:United States
Contact:

-

Post by Williamnen » Sat Nov 27, 2021 8:26 pm

Sorry I didnt come back to this post sooner, I tried editing in the later posts, and that worked.. but the 1st post still wont let me edit it.. weird puter gremlin stuff..


.

xnewsruc
Posts:1
Joined:Sun Nov 28, 2021 2:48 am

Супер важные news

Post by xnewsruc » Mon Dec 13, 2021 4:36 am

Супер шокирующие news на новостном портале xnews press . Самое из самых изданий

ChinaawamP
Posts:42
Joined:Thu Dec 30, 2021 7:53 pm
Location:http://product-of-china.cf/
Contact:

-

Post by ChinaawamP » Sun Jan 23, 2022 5:00 pm

Its certain characters in the fonts, most can be fixed in the Apple stuff that benbaboon found, not researching which ones it is for everyone else.

Post Reply