The "old" way to declare variables in JavaScript is with the var keyword. These days var still works, but I'd advise you to avoid it completely in new code. None of this:
var mySkillIssues = 42;
Instead, use let:
let mySkillIssues = 42;
Or const (short for constant) for values that you never expect to change:
const mySkillIssues = 42;
If you try to reassign a const variable, you'll get an error:
const mySkillIssues = 42;
mySkillIssues = 43; // TypeError: Assignment to constant variable.
Whereas with let, you can reassign the value without issue:
let mySkillIssues = 42;
mySkillIssues = 43; // No error
Use let for variables that you'll need to reassign, and const when you won't.
var?The big problem with var is that it's function-scoped, not block-scoped, which leads to unexpected behavior. Most developers expect block scope. Here's an example of the difference:
if (true) {
var mySkillIssues = 42;
}
console.log(mySkillIssues); // 42
mySkillIssues isn't scoped to its block (the if body), as most developers would expect. Instead, it's scoped to the function that contains it (or the global scope if it's not in a function). The let and const keywords are block-scoped:
if (true) {
let mySkillIssues = 42;
const myConstSkillIssues = 43;
}
console.log(mySkillIssues); // ReferenceError: mySkillIssues is not defined
console.log(myConstSkillIssues); // ReferenceError: myConstSkillIssues is not defined
There is a bug with the Textio code that sends messages on user's birthdays, it's sending them two birthday messages! Fix the var declarations so that each variable has the correct scope and behaves as expected.