Variables can hold values with the following different data types:
- Objects and symbols
If you see what looks like a variable name followed by parentheses, it is probably a function. The parentheses contain arguments, which should be separated by commas if there are multiples.
HTML events include actions both by the user and the browser.
The smallest possible structure while writing code is called an Expression. An expression is anything that is a value or maybe the outcome in a piece of code.
2 + 3 is an expression because it produces a value that is
A statement is basically interchangeable with an expression. However, a statement is more of an instruction or one line of code that instructs the browser in this case to perform a task or carry out an operation.
result = 2 + 3 is a statement because it does not necessarily produce a value but it does instruct the browser to store the value
5 in a variable called
Semantics in contrast to syntax is the actual meaning of the programming language construct like an expression or a statement. It describes how the script or the program might be executed. It could also describe the browser or the platform on which the code is running and the input/output parameters needed to successfully execute the program. A piece of code with invalid syntax cannot be evaluated semantically because it is of an invalid structure not acceptable by the language.
Clean code means fewer bugs to troubleshoot, better code security, and an easier time involving other Programmers. Clean code can also be converted by scripts to other formats, rather than requiring human intervention.
Global variables and local variables
Every variable used in a function should be declared as a local variable (they should be declared either with the var or let keyword or they will become global variables).
You should avoid declaring string, number, and boolean as objects because it can greatly slow execution speed and lead to a host of unwanted side issues.
Block scored declarations
Be specific with names
Again, to avoid slowing things down with unnecessary confusion, try to avoid using one-letter names. (An exception could be made for extremely common names.)
Although short names are generally better than long ones, it might be worth opting for a longer name in certain situations where the extra description will greatly help clarity.
When you name a variable, the name should be clear and detailed enough that it leaves no doubt about what it is used for. Again, you shouldn’t need to write comments just to define variables.
Begin function names with a verb, since they’re used to perform actions. Try to be consistent with the same verbs for the same actions — this is not an area where you want to get creative with your verb choices.
Class and file names
Get hands-on experience writing code with interactive tutorials in our free online learning platform.
- Free and fun
- Designed for beginners
- No downloads or setup required