Assessment request for my variables 1 skill test

Hi. Any assessment appreciated. Thank you and have a good day!

variables1
variables2
variables3

I like to use const over let, unless the variable is reassigned a new value later in time (If you declare a variable as const and you try to reassign it you will have a runtime error).
For the first task - in this case both name and age aren’t reassigned new values so I would make them constants. Note that MDN’s code itself doesn’t follow this standard (let para1 and let para2 which should also be constants.
2nd - here the variable is reassigned a value so it’s not a constant and we have to use let.
3rd - myAge can be const

1 Like

Hi @harryghgim!

You’ve done some great work here, and your code works fine. I had a few small comments:

  1. In the first question, you are asked to declare the myName variable and then initialize it with a value on the second line. So strictly speaking, the code should be
let myName;
myName = 'Harry';
let myAge  = 32;

But this is really just a nitpick — your code works fine, as is more likely what you’d do in a real world example.

Answer number 2 is perfect.

Answer number 3 is perfect.

@aviv.mu is not wrong here — strictly speaking const should be used for values that will never change in an app. And they are also right that we don’t follow this best practice everywhere on MDN (it’s a nightmare the keep it all consistent…we’ve tried :wink: )

You should start thinking about these semantics as you start to build bigger JS apps, however, I think that at this stage it is more important to work on getting your code running without errors, than worry too much about the semantics of variables. Keep it in midn though.

Also consider this — when you are just playing with simple code, it is often better to declare everything with let, in case you decide you want to change those values later on. When you’ve finished putting a simple example together, you can then look to change the variables that are never changed to use const.

Of course, when build a larger, more complex app, this is not such a good idea — in a larger codebase, const becomes a useful developer tool, as it will throw an error if you accidently try to change its value.

1 Like