Tuesday, 14 October 2014

JavaScript Syntax

JavaScript is a scripting language. A scripting language is a lightweight programming language.
The sentences in a programming language are called statements.
The principles, how sentences are constructed in a language, are called language syntax.

JavaScript Literals

In a programming language, a literal is a constant value, like 3.14. Number literals can be written with or without decimals, and with or without scientific notation (e):
3.14
1001
123e5
 String literals can be written with double or single quotes:
"John Doe"
'John Doe'
Expression literals evaluate (compute) to values:
5 + 6
5 * 10
Try it Yourself »
Array literals defines an array:
[40, 100, 1, 5, 25, 10]
Object literals defines an object:
{firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"}
Function literals defines a function:
function myFunction(a, b) { return a * b;} 

JavaScript Variables

In a programming language (and in algebra), variables are used to store data values.
JavaScript uses the var keyword to define variables.
An equal sign is used to assign values to variables (just like algebra).
In this example, length is defined as a variable. Then, it is assigned (given) the value 6:
var length;
length = 6;
Try it Yourself »


A literal is a fixed value. A variable is a name that can have variable values.

1 comment:

  1. Custom pressing corners have moved in the path of swinging into to be clear, and their characteristic intrigue has restored. Within the beginning, it isn’t always in every case usually challenging to find out Custom Printed Boxes which can be advanced possibly made via the subtleties of the supporter’s attitude.

    ReplyDelete