Naming conventions in Javascript or rather in the programming world is a very essential, important and effective skill to harness and develop as a beginner looking to adopt coding or programming as a career, this is a very important part most developers don't pay attention to. As a beginner you should make it your very tool to ensure you name your variables as unique as to the function or program you are coding. For example, Programmer "A" needs to write a to-do-list functions and he gave his function the name and variables;
function todoList() {
const tasks = [];
while (true) {
const task = prompt("Enter a task or type 'done' to exit:");
if (task === 'done') {
break;
}
tasks.push(task);
}
console.log("Your to-do list:");
tasks.forEach(task => console.log("- " + task));
}
pretty straightforward right? Exactly, Programmer A had to give an explanatory name to the function { todoList} which shows exactly what he is trying to achieve, unlike Programmer B, that has his functions that also runs but with confusing variable names below;
function firstCodes() {
const three = [];
while (true) {
const task = prompt("Enter a task or type 'done' to exit:");
if (task === 'done') {
break;
}
three.push(three);
}
console.log("Your to-do list:");
three.forEach(three => console.log("- " + three));
}
these two codes above performs same action but one is more explanatory and in a code-like fashion and the other is just a bunch of confusing scripts due to not having unique name similar to intended tasks needed to achieve.
As we all know naming is the first part you need to undesrtand about programming, if this foundation isn't strong, pogramming will be difficult to grasp. So imbibe the culture to name rightly, I have made available below some naming conventions that are right and wrong with some examples.
// Naming conventions
// let message = "This is my first message" // ✅
// let message2 = "This is my second message" // ✅
// let user_name = "AdeJ123" // ✅
// let myReallyLongName = "Ade Johnson" // ✅
// let 1message = "This is my first message" // ❌
// let user-name = "AdeJ123" // ❌
// let myreallylongname = "Ade Johnson" // ❌
// Variable declaration (const)
// const NAME = "Ade Johnson" ✅
// NAME = "Adewale Johnson" //❌ //error, cannot re-assign to a constant variable
// const NAME = "Ade Johnson" // ✅
// const name = "Ade Johnson" // ❌
// const MY_BIRTHDAY = "5th July 2000" // ✅
// const MYBIRTHDAY = "5th July 2000" // ❌
// Variable declaration (let)
// let name = "Ade Johnson"
// name = "Adewale Johnson" //✅
// const myBirthday = "5th July 2000" // ✅
// const mybirthday = "5th July 2000" // ❌
Goodluck on your programming journey ahead.... rooting for you.