JavaScript Identifer Naming

Account Required

This free lesson is available if you sign in.
If you don't have an account, you can sign up for free.

Professional Modern JavaScript Lessons

1.Course Intro
free
⏱️ 1:13
2.Setup & Tooling
free
⏱️ 3:32
3.Debugger Statements and Breakpoints
free
⏱️ 2:17
4.Primitive Data Types and Values
free
⏱️ 3:06
5.JavaScript Variables - let and const
free
⏱️ 4:50
6.Comments in JavaScript
free
⏱️ 2:55
7.JavaScript Identifer Naming
free
⏱️ 2:52
8.Using TypeScript
free
⏱️ 4:26
9.JavaScript String Masterclass
free
⏱️ 9:29
10.JavaScript Boolean Type
⏱️ 6:45
11.Missing Guide to JavaScript Numbers
⏱️ 15:28
12.JavaScript Objects Demystified
⏱️ 13:33
13.Functions in JavaScript
⏱️ 20:25
14.JavaScript Arrays Masterclass
⏱️ 22:31
15.JavaScript If Else Statements and Best Practices
⏱️ 6:13
16.JavaScript Conditional Expressions
⏱️ 8:38
17.JavaScript Loose vs Strict Equality
⏱️ 4:02
18.Truthy vs Falsy in JavaScript
⏱️ 3:44
19.Concept of JavaScript Nullish and Unification
⏱️ 5:51
20.JavaScript Classes - Object Oriented Programming
⏱️ 10:30
21.JavaScript Error Handling and Exceptions
⏱️ 13:21
22.JavaScript Nullish Operators
⏱️ 5:48
23.JavaScript Switch Statement Masterclass
⏱️ 8:07
24.JavaScript For Loop Iteration Simplified
⏱️ 10:59
25.JSON Masterclass
⏱️ 7:59
26.JavaScript While and Do While Loops
⏱️ 2:52
27.JavaScript Date and Time Simplified
⏱️ 13:16
28.this in JavaScript
⏱️ 12:04
29.JavaScript Tagged Templates Masterclass
⏱️ 5:48
30.Promises in JavaScript
⏱️ 10:01
31.JavaScript Async Await Masterclass
⏱️ 9:00
32.JavaScript Symbols Demystified
⏱️ 7:25
33.JavaScript Iterators and Iterables
⏱️ 8:50
34.JavaScript Generators Simplified
⏱️ 9:17
35.JavaScript Prototype - The Secret Guide
⏱️ 11:21
36.JavaScript Set Builtin Data Structure
⏱️ 9:52
37.JavaScript Map Builtin - HashMap Magic
⏱️ 10:38
38.JavaScript Deferred Promise Pattern - withResolvers
⏱️ 3:35
39.Cloning and Deep Copying in JavaScript
⏱️ 3:14
40.JavaScript Async Await Sequencing and Execution Masterclass
⏱️ 10:31
41.JavaScript Memory Management Masterclass
⏱️ 5:26
42.JavaScript WeakMap Demystified
⏱️ 8:58
43.JavaScript bigint Masterclass
⏱️ 5:35
44.JavaScript WeakSet Explained with Examples
⏱️ 7:47
45.JavaScript Regular Expressions Masterclass
⏱️ 17:54
46.JavaScript Weak References Demystified
⏱️ 5:29
47.JavaScript Memory Leaks Demonstrations and Fixes
⏱️ 6:01
48.Semicolon Free Coding in JavaScript
⏱️ 3:46
49.JavaScript Modules Masterclass
⏱️ 11:36

JavaScript Identifer Naming

Sign in to access this content

You must sign in to access this content.
If you don't have an account you can sign up for free!

Valid

let allowed;
let $allowed;
let _allowed;
let ällowed;

Digits

let allowed0;
let all0wed;
let 0invalid; // ERROR

Case Sensitive

// These are different variables
let Allowed;
let aLlowed;

Various Character Sets

const favourite🌹; // ERROR
const ಠ_ಠ = 42; // OK
const π = 3.14; // OK

Naming Conventions

let firstName; // camelCase - Most things JS ✅
let FirstName; // PascalCase - only for classes and special library things (like React Components) ✅
const FIRST_NAME = 'John'; // CAPITAL_SNAKE_CASE - for immutable constants ✅

let first_name; // snake_case - Allowed but not used often ❌
let first-name; // ERROR: kebab-case is not a valid identifier ❌
javascript
typescript
react
playwright

Enjoy free content straight from your inbox 💌

No spam, unsubscribe at any time.

Transcript

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.

Professional Modern JavaScript

Professional Modern JavaScript

1.Course Intro
free
⏱️ 1:13
2.Setup & Tooling
free
⏱️ 3:32
3.Debugger Statements and Breakpoints
free
⏱️ 2:17
4.Primitive Data Types and Values
free
⏱️ 3:06
5.JavaScript Variables - let and const
free
⏱️ 4:50
6.Comments in JavaScript
free
⏱️ 2:55
7.JavaScript Identifer Naming
free
⏱️ 2:52
8.Using TypeScript
free
⏱️ 4:26
9.JavaScript String Masterclass
free
⏱️ 9:29
10.JavaScript Boolean Type
⏱️ 6:45
11.Missing Guide to JavaScript Numbers
⏱️ 15:28
12.JavaScript Objects Demystified
⏱️ 13:33
13.Functions in JavaScript
⏱️ 20:25
14.JavaScript Arrays Masterclass
⏱️ 22:31
15.JavaScript If Else Statements and Best Practices
⏱️ 6:13
16.JavaScript Conditional Expressions
⏱️ 8:38
17.JavaScript Loose vs Strict Equality
⏱️ 4:02
18.Truthy vs Falsy in JavaScript
⏱️ 3:44
19.Concept of JavaScript Nullish and Unification
⏱️ 5:51
20.JavaScript Classes - Object Oriented Programming
⏱️ 10:30
21.JavaScript Error Handling and Exceptions
⏱️ 13:21
22.JavaScript Nullish Operators
⏱️ 5:48
23.JavaScript Switch Statement Masterclass
⏱️ 8:07
24.JavaScript For Loop Iteration Simplified
⏱️ 10:59
25.JSON Masterclass
⏱️ 7:59
26.JavaScript While and Do While Loops
⏱️ 2:52
27.JavaScript Date and Time Simplified
⏱️ 13:16
28.this in JavaScript
⏱️ 12:04
29.JavaScript Tagged Templates Masterclass
⏱️ 5:48
30.Promises in JavaScript
⏱️ 10:01
31.JavaScript Async Await Masterclass
⏱️ 9:00
32.JavaScript Symbols Demystified
⏱️ 7:25
33.JavaScript Iterators and Iterables
⏱️ 8:50
34.JavaScript Generators Simplified
⏱️ 9:17
35.JavaScript Prototype - The Secret Guide
⏱️ 11:21
36.JavaScript Set Builtin Data Structure
⏱️ 9:52
37.JavaScript Map Builtin - HashMap Magic
⏱️ 10:38
38.JavaScript Deferred Promise Pattern - withResolvers
⏱️ 3:35
39.Cloning and Deep Copying in JavaScript
⏱️ 3:14
40.JavaScript Async Await Sequencing and Execution Masterclass
⏱️ 10:31
41.JavaScript Memory Management Masterclass
⏱️ 5:26
42.JavaScript WeakMap Demystified
⏱️ 8:58
43.JavaScript bigint Masterclass
⏱️ 5:35
44.JavaScript WeakSet Explained with Examples
⏱️ 7:47
45.JavaScript Regular Expressions Masterclass
⏱️ 17:54
46.JavaScript Weak References Demystified
⏱️ 5:29
47.JavaScript Memory Leaks Demonstrations and Fixes
⏱️ 6:01
48.Semicolon Free Coding in JavaScript
⏱️ 3:46
49.JavaScript Modules Masterclass
⏱️ 11:36