Activity
Mon
Wed
Fri
Sun
Jun
Jul
Aug
Sep
Oct
Nov
Dec
Jan
Feb
Mar
Apr
May
What is this?
Less
More

Memberships

Senior Dev Academy

Public ā€¢ 652 ā€¢ Free

2 contributions to Senior Dev Academy
hoisting exercise
Hi there! So my solution for the exercise was this: // Fix the code below to make the function return 12 function calculate() { a = 4; b = 3; return a * b; // Should return 12 } let a; ... but the solution branch suggests this: function calculate() { const a = 4; const b = 3; return a * b; // Should return 12 } ... I didn't quite understand what the exercise is asking us to do, nor why the solution is using const - would it be possible to get a bit more information on why the solution on the solution branch is the best? Thanks in advance!
5
2
New comment Nov '23
4 likes ā€¢ Nov '23
Hi, Your solution is technically valid, but the logic behind isn't clear. You declare your variables outside of the function but assign and use them in the function. The approach of the solution makes more sense, variables used in a function should only be declared in the scope of this function. And since the values are assigned and never changed, "const" is the better choice over "let". Well, that is what I can tell with my understanding. Anyone, feel free to correct me if I'm wrong
What's your tech stack?
Comment below with your tech stack :)
18
40
New comment Nov '23
5 likes ā€¢ Oct '23
Mainly Typescript and Angular, with a bit of Node.js and very little C#
1-2 of 2
Renaud Moiselet
2
11points to level up
@renaud-moiselet-5589
Became a developper 5 years ago after a career shift

Active 9d ago
Joined Oct 17, 2023
powered by