Enjoy free content straight from your inbox 💌
00:00
There is a saying that the two hardest things in programming are cash invalidation, naming things, and off by one errors. Even though naming things are hard, what is technically possible as an identifier name within JavaScript is quite easy to discuss, which is exactly what we will do in this tutorial and also cover some basic naming conventions. So let's go first up. The set of valid characters for JavaScript identifiers are the underscore dollar or any Unicode letter. This means that all of the variable names that we see over here are valid identifiers. In addition to these,
00:32
the JavaScript runtime also allows digits to be a part of an identifier. However, there is a restriction that the digit cannot be the first character. So as an example, if you put zero at the start of the identifier, the JavaScript runtime, we'll throw an error. Another thing to note with the JavaScript is that the variable names are case sensitive. So these two are distinct variables for the well set. We've used this term called Unicode letter, which is a loose term, but basically means characters you see in various global scripts are okay, but it doesn't include all Unicode characters. For example,
01:07
an emoji in an identifier will result in an error. Now, even though an emoji might be ruled out, it does mean that you can do some pretty crazy stuff, for example, create this thing for the meaning of everything. However, I would recommend sticking to the standard Latin characters for everyone's convenience. Now, you might argue that there are valid cases. For example, you could use the pie character for the pie variable, but again, I would highly recommend it not doing this because it is going to be a torture for someone to type without a special keyboard. Now, let's talk a bit about naming conventions. Most commonly in JavaScript,
01:42
you will be using camel casing, but there are circumstances where developers will use something else. Now, one thing that does look good, however it is almost never used by JavaScript developers is the snake case. As mentioned, for most things within JavaScript, people will use camel casing. The other common identifier convention is Pascal casing. And we use this when we are working with classes or when we want to declare something special that a library expects, for example, react components. And the final convention that we find within JavaScript is Capital Snake Case, which people use for immutable Constance. Now,
02:19
in terms of the big forms of naming conventions, the final one that you might be curious about is case, but fortunately, you don't have to worry about anybody using it in your code base because this is not a valid JavaScript identifier because the dash is considered a minus sign by the JavaScript runtime and does not become a part of the identifier. And in terms of naming things, don't stress too much. As you read and write a more and more code, you will naturally start to improve your naming skills. As always, thank you for joining me and I will see you in the next one.