03 1 of 2 JavaScript - Variables & Data Types
03 1 of 2 JavaScript - Variables & Data Types
What is Variable?
Variables are used to store data, like string of text, numbers, etc. The data or
value stored in the variables can be set, updated, and retrieved whenever needed.
In general, variables are symbolic names for values.
You can create a variable with the var keyword, whereas the assignment operator (=)
is used to assign value to a variable, like this: var varName = value;
Naming Conventions for JavaScript Variables
A variable name must start with a letter, underscore (_), or dollar sign
($).
// Creating variables
document.write(name + "<br>");
document.write(age + "<br>");
document.write(isStudent );
</script>
Lets add one more variable, we shall name it isStudent
Example
<script>
// Creating variables
document.write(name + "<br>");
document.write(age + "<br>");
document.write(isStudent + <“br”>);
document.write(qualification);
</script>
Javascript Data Types
Data Types in JavaScript
Data types basically specify what kind of data can be stored and manipulated within a
program.
There are eight basic data types in JavaScript which can be divided into three main categories:
primitive (or primary), composite (or reference), and special data types. String, Number,
and Boolean are primitive data types. Object, Array, and Function (which are all types of objects)
are composite data types. Whereas Undefined and Null are special data types.
Primitive data types can hold only one value at a time, whereas composite data types can
hold collections of values and more complex entities. Let's discuss each one of them in
detail.
In a nutshell
JavaScript primitive data types
Data Description
Type
Object represents instance through which we can
access members
Array represents group of similar values
RegExp represents regular expression
Example
<script>
</script>