Js Syntax
# JavaScript Syntax
* * *
JavaScript is a programming language. Syntax rules define the structure of the language.
* * *
## JavaScript Syntax
JavaScript is a scripting language.
It is a lightweight yet powerful programming language.
* * *
## JavaScript Literals
In programming languages, fixed values are generally called literals, such as 3.14.
**Number literals** can be integers or decimals, or in scientific notation (e).
3.14
1001
123e5
[Try it Yourself Β»](#)
**String literals** can use single quotes or double quotes:
"John Doe"
'John Doe'
[Try it Yourself Β»](#)
**Expression literals** are used for computation:
5 + 6
5 * 10
[Try it Yourself Β»](#)
**Array literals** define an array:
[40, 100, 1, 5, 25, 10]
**Object literals** define an object:
{firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"}
**Function literals** define a function:
function myFunction(a, b) { return a * b;}
* * *
## JavaScript Variables
In programming languages, variables are used to store data values.
JavaScript uses the keyword **var** to declare variables, and the equal sign to assign values to variables:
var x, length
x = 5
length = 6
[Try it Yourself Β»](#)
Variables can be accessed by their variable names. In imperative languages, variables are typically mutable. A literal is a constant value.
|  | A variable is a **name**. A literal is a **value**. |
| --- |
* * *
## JavaScript Operators
JavaScript uses **arithmetic operators** to compute values:
(5 + 6) * 10
[Try it Yourself Β»](#)
JavaScript uses **assignment operators** to assign values to variables:
x = 5
y = 6
z = (x + y) * 10
[Try it Yourself Β»](#)
The JavaScript language has several types of operators:
| Type | Example | Description |
| --- | --- | --- |
| Assignment, Arithmetic, and Bitwise Operators | = + - * / | Described in JS Operators |
| Conditional, Comparison, and Logical Operators | == != | Described in JS Comparison Operators |
* * *
## JavaScript Statements
In HTML, JavaScript statements are used to send commands to the browser.
Statements are separated by semicolons:
x = 5 + 6;
y = x * 10;
* * *
## JavaScript Keywords
JavaScript keywords are used to identify the actions to be performed.
Like any other programming language, JavaScript reserves some keywords for its own use.
The **var** keyword tells the browser to create a new variable:
var x = 5 + 6;
var y = x * 10;
JavaScript also reserves some keywords that are not used in the current version of the language, but will be used in future JavaScript extensions.
The following are the most important reserved keywords in JavaScript (in alphabetical order):
abstract else instanceof super
boolean enum int switch
break export interface synchronized
byte extends let this
case false long throw
catch final native throws
char fina
YouTip