+ 1

Variable Naming Best Practise for JavaScript

I learn from the JavaScript course here that there are 3 ways to name a variable. You should start with: 1. Letter 2. Underscore _ 3. Dollar Sign $ So I was wondering if what is the best way or practice for naming variable? I'm also coding with PHP. and in PHP, you declare variable by using dollar sign $. I'm thinking of starting practicing and using dollar sign $ for my future JavaScript codes for consistency with PHP but I'm not sure if it is a good practice. if not, any reason why? I rarely seeing JavaScript codes (or I did not see at all) that uses dollar sign in their variable name, so I was wondering if it is a good practice for the future codes.

22nd Apr 2018, 7:06 AM
Raffy
Raffy - avatar
3 odpowiedzi
+ 2
just use names that describe, what the variable is for, so you can understand the code later. Don't start with a special character, just write the name
22nd Apr 2018, 10:13 AM
Moritz Vogel
Moritz Vogel - avatar
+ 2
The worst thing that can happen is that you come back after a while and you don't understand your own code. Try to name your variables so that another person could understand your code easily.
22nd Apr 2018, 11:36 AM
Jonas Schröter
Jonas Schröter - avatar
+ 1
thank you for all the tips!
23rd Apr 2018, 12:31 AM
Raffy
Raffy - avatar