In javascript programming, it is useful to give meaningful variable names that are easier to remember, recall and understand. Instead of calling the variable that holds country names 'x', we called it 'countryname', this helps in better programming as when working with thousand of lines of codes, you will forget what x refered to. but the word countryname will tell you what the variable actually holds.
Basic Rules
It can contain letters, numbers and some symbols.
First character of the variable name should be a letter or an underscore. It cannot start with a number.
What cannot be used as Variable names
Javascript reserved words like var, with , .. etc that are used by javascript as commands
Variables names cannot contain blank spaces. if you want to separate words in a variable name, used Underscore '_' Ex. 'student_age'
Ampersand & or the Percent sign % cannot be used.
Variable name cannot start with a number however in later characters(after first one), numbers can be used.
Case Sensitivity
In javascript variable names are case sensitive. Variable names 'studentage', 'Studentage' and 'STUDENTAGE' are considered different variables. Although the letters are same but the case is different in all the three names.
Hungarian notation
JavaScript tutorials
Advance user concept- (you can skip this Paragraph if you want to).
Although variable types are not declared in javascript, it is good programming practice to add a prefix to the variable name describing the type of data you wish to assign with the data. For example, variable studentage will be assigned a numeric value. So we might want to name it num_studentage
a Variable student name that will hold string(text) data might be called str_studentname
Basic Rules
It can contain letters, numbers and some symbols.
First character of the variable name should be a letter or an underscore. It cannot start with a number.
What cannot be used as Variable names
Javascript reserved words like var, with , .. etc that are used by javascript as commands
Variables names cannot contain blank spaces. if you want to separate words in a variable name, used Underscore '_' Ex. 'student_age'
Ampersand & or the Percent sign % cannot be used.
Variable name cannot start with a number however in later characters(after first one), numbers can be used.
Case Sensitivity
In javascript variable names are case sensitive. Variable names 'studentage', 'Studentage' and 'STUDENTAGE' are considered different variables. Although the letters are same but the case is different in all the three names.
Hungarian notation
JavaScript tutorials
Advance user concept- (you can skip this Paragraph if you want to).
Although variable types are not declared in javascript, it is good programming practice to add a prefix to the variable name describing the type of data you wish to assign with the data. For example, variable studentage will be assigned a numeric value. So we might want to name it num_studentage
a Variable student name that will hold string(text) data might be called str_studentname
Aucun commentaire:
Enregistrer un commentaire