
JavaScript
JavaScript Syntax
JavaScript syntax determines the rules and format used to write any JavaScript code. The JavaScript code is written and organised for a program, guided by JavaScript syntax.
JavaScript Values
JavaScript syntax has the following values:
- Fixed values/ or literals and
- Variable values or variables
JavaScript Literals
In JavaScript, literals are fixed values. The rules for writing these values are:
- Express numbers with or without a decimal point.
- Another value of literals is the string, which is a text written inside double or single quotes.
JavaScript Variables
In any programming language, a variable is a unit that stores data values. In JavaScript, keywords are used to specify a variable, such as let, var, or const. An equal sign ( = ) is used to assign values to JavaScript variables.
JavaScript Operators
In programming, JavaScript uses arithmetic symbols or operators (+, -, *, / ) to perform mathematical calculations.
JavaScript Expressions
A JavaScript expression is not a single value. It consists of values, variables, and operators, and the shown result has all these values. Computation in programming is also known as evaluation.
Keep in mind that the JavaScript value can be either a number, a string, a group of numbers, or a combination of strings.
JavaScript Keywords
JavaScript identifies an action with the keyword written. So, JavaScript keywords declare a function or action to be performed.
JavaScript Comments
JavaScript statements contain the information about the functions that JavaScript will perform. However, not every JavaScript statement is meant to be executed. Any function that a developer does not wish to execute can be written as a JavaScript comment. Its code can be written in two ways:
- double slashes // or
- between /* and */
The JavaScript program ignores any code that has these values.
JavaScript Identifiers / Names
In JavaScript, identifiers are its names. Variables, keywords, or functions in JavaScript are named by identifiers. Naming JavaScript values has a rule that the value should start with one of the following:
- A letter (A-Z or a-z)
- A dollar sign ($)
- Or an underscore (_)
No name in JavaScript begins with a number. This practice distinguishes JavaScript identifiers from numbers.
JavaScript is Case Sensitive
JavaScript identifiers are case sensitive. The variable’s last name and the last name of a name are not the same variable.
JavaScript and Camel Case
JavaScript lets you join multiple words to convert them into a single variable name. Programmers do it in the following ways:
- Hyphens (first-name, second-name, etc.)
Note that hyphens are used in JavaScript only for substractions.
- Underscore (first_name, second_name)
- Upper Camel Case or Pascal Case (FirstName, SecondName)
- Lower Camel Case (firstName, lastName)
JavaScript Character Set
In JavaScript, programmers use Unicode character sets. The Unicode character sets include all the characters, punctuation marks, and symbols that are universally used.