Javascript Variable Data Type


Javascript Variable Data Type

In JavaScript, we do not need to declare the types of variables we will use, otherwise the language of another programming language (which is more advanced) like C or Java. We have to declare in detail whether the variable used is an integer (int), decimal (float), character (char), and other ...

Actually in JavaScript itself, we can only manipulate 4 types of data are:

  • Numbers: round or decimal, which we refer to as integer or float
  • Word (a collection of letters): we call the string
  • Boolean: a variable that has two values and serves to check a condition: true: if the condition is true, false: if the condition is false
  • Variables with null type: a specific word (including the keywords as well) to explain that there is no data in it.

Integer
Integer can be shown in some of the following basis:
  • decimal base: integer in the write in the order of unit numbers (from 0 to 9), the beginning numbers should not be initiated by a 0
  • hexadecimal base: the sequence is written in units of numbers from 0 to 9 or a sequence of letters from A through to F (or a through f), the beginning numbers starting by 0x or 0X
  • octal base: the sequence is written in units of numbers from 0 to 7, the beginning numbers starting with 0

Float (decimal number)
Decimal number can be called as well as fractions or numbers that we can write by using a comma. This number can also be written in the following ways :
  • decimal integer: 895
  • numbers with commas: 895.12
  • division number: 27/11
  • exponential numbers: numbers with a comma, followed by the letter e (or E), followed by an integer, which means the rank of number 10 (+ or -, positive or negative), for example:
var a = 2.75e-2;
var b = 35.8E +10;
var c = .25 e-2;
String String is a collection of characters, we declare a string variable using the mark (') or ("), both of these markers should be used in pairs and can not be used individually or mixed. Here are some ways to declare string variables:
var a = "Hello";
var b = 'Nice to see you!';
There are several special characters that we can use to simulate the part of characters that are not visible (non-visual) and also to avoid the possibility of the navigator "confused" in distinguishing between the string and the script itself, these special characters using the backslash symbol (\), here is some special character examples :
  • \n : back to start line
  • \r : pressing the ENTER key
  • \t : tab
  • \" : double quotes
  • \' : single quotes
  • \\ : backslash character
 
For example we want to save the variable title (string) the following:
There is data in "c:\windows\" 
We have to write it in the form below in JavaScript:
Title = "There is data in \"c:\\windows\\\"";
Or it could be in the following way (using single quotation marks):  
Title = 'There is data in "c:\\windows\\"';
To manipulate a String variable, JavaScript has an object named String object, which consists of several methods to create and manipulate string variables.

Booleans Boolean is a special variable that is useful to evaluate a certain condition, boolean has two values:
  • True: represented by value 1
  • False: represented by value 0

0 comments:

Post a Comment