Why use dollar sign for a variable name? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why use dollar sign for a variable name?

18th Jan 2017, 9:42 PM
mich
3 Answers
+ 3
You use dollar signs in PHP not JS.
19th Jan 2017, 1:12 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 3
Php --> $ is required to start a variable name JS --> $ is valid character for variable name, even at first position or alone ( as is named the main variable/function of JQuery function )
19th Jan 2017, 7:29 AM
visph
visph - avatar
+ 2
This is totally related to language design. $ sign is required to be first character of the variable name in php language and this makes php interpreter faster to lexical analyze your code and determine which word is a variable name. $ sign isn't required to be first character of the variable name in Javascript but you can use it if you like.
19th Jan 2017, 7:50 AM
Ahmad
Ahmad - avatar