JavaScript Tutorial – Syntax and Statements
What is JavaScript Syntax
JavaScript syntax is the set of rules that define a correctly structured JavaScript program. In this tutorial, you will learn everything you need to know about JavaScript syntax, including keyword, statements, whitespaces, semicolons.
JavaScript Statement
Statements are the instructions for the computer to execute and they are separated by semicolons. Semicolons are optional if each of the statements are placed on a separate line, but it is recommended that you end a statement with a semicolon, it is just much cleaner to read.
let name, age; // first statement
name = "Jay"; // second statement
age = "21"; // third statement
JavaScript Value
JavaScript syntax has two type of values:
- Fixed value
- Variable value
Fixed values are called JavaScript literals. Examples are numbers and strings. Numbers are written with or without decimals, and Strings are text, written within double or single quotes.
10 // number
10.35 // number
"Hello" // string
"Jay" // string
Variable values are called variables. JavaScript variables are used to store data values and they are defined with the var
, let
or const
keyword. An equal sign is used to assign values to variables.
var website = "WhatAboutHTML";
JavaScript Keyword
Keywords are reserved words and cannot be used as variables or function names. They are used to identify actions to be performed. In the above example, keyword var
and let
tell the browsers to create a new variable.
What is Camel Case
Camel Case is the practice of writing compound words or phrases such that each word or abbreviation begins with a capital letter. With JavaScript, it is highly recommended that you start with a lowercase letter. See below examples.
var myName;
var myCarColor;
JavaScript is case sensitive
This is very important, variable mycarcolor is not the same as myCarColor. JavaScript sees them as two different variables.
var mycarcolor = "red";
var myCarColor = "blue";