Variables and Datatype
Variables and Datatype
Variables –
Following are some basic definitions of variables in a typical programming language context.
A variable provides us with a named storage that our programs can manipulate. It is the basic unit of storage in a program.
Variables are used to store information to be referenced & manipulated in a computer program.
In programming, a variable is a value that can be changed depending on the conditions or information being passed to the program.
Data Types –
Datatypes are basically type of data that can be used and manipulated in a program. For e.g. numbers(1, 2, 5,5), string(“hello Simple Snippets”, “JS”), boolean(true, false) etc.
JavaScript Numbers –
JavaScript has only one type of numbers. Numbers can be written with, or without decimals:
JavaScript Booleans –
Booleans can only have two values: true or false. Booleans are often used in conditional testing.
Example –
1var x;
2x = 5;
In the above example we can see that we did not have to specify any data type for the variable x in advance.
Example –