JS Basic Tutorial
In JavaScript, variables are containers for storing data values. They can hold different types of data, such as numbers, strings, objects, arrays, and more.
JavaScript Variables can be declared in 4 ways:
Try it yourself
Try it yourself
Try it yourself
In JavaScript, identifiers are names used to identify variables, functions, arrays, objects, or any other user-defined items. They must follow specific rules to be valid.
The general rules for constructing names for variables (unique identifiers) are:
Must begin with a letter, underscore (_
), or dollar sign ($
): Names must begin with a letter.
Can contain letters, digits (0-9), underscores (_
), or dollar signs ($
): after the first character: Names are case sensitive (y and Y are different variables).
Names are case sensitive (y and Y are different variables).
Reserved words (like JavaScript keywords) cannot be used as names.
Note
Some of reserved words are
- break
, case
, catch
, class
, const
, continue
, debugger
, default
, delete
, do
, else
, export
, extends
, finally
, for
, function
, if
, import
, in
, instanceof
, let
, new
, return
, super
, switch
, this
, throw
, try
, typeof
, var
, void
, while
, with
, yield
1. Valid
2. Invalid
Best Practices:
Use meaningful and descriptive names for identifiers to make your code more readable.
Stick to camelCase for variable and function names (myVariableName).
Use uppercase for constants (MAX_VALUE).