In this chapter, you will learn a list of data types available in Javascript.
String Data Type
String data type in Javascript represents a 16 bits characters. If you want to declare a text value, you can use string data types. See below code example on how to use it.
//declare a string var myName = "Hello bytutorial"; //alternatively, you can use a single quote for the string var myName = 'Hello bytutorial';
Number Data Type
Number data type in Javascript represents integers and floating point numbers. See below code example on how to use it.
// integer number var myNumber = 1000; // float numbers var myHeight = 175.24;
Boolean Data Type
Boolean data type in Javascript represents true or false value only. See below code example on how to use it.
// using false value var useNumber = false; // using true value var isCorrect = true;
Null Data Type
Null data type in Javascript represents null value or empty object pointer. See below code example on how to use it.
//this is how you set the null value var currentValue = null; //this is how you check it if(currentValue != null){ //do something in here. }
Object Data Type
Object data type in Javascript represents an object type creation. This type of object can be created by using a operator called new. You will learn more details about this data type in Object Oriented in Javascript in the upcoming chapter. See below code example on how to use it.
var myObject = new Object();
How to detect a data type in Javascript?
As the data type in Javascript is flexible or loosy types, luckyly there is a built in operator you can use. The operator is named typeof. See below code example on how to use it.
// integer value var myNumber = 100; // string value var myName = "Hello bytutorial"; //to get the data type you can use this alert(typeof(myNumber)); alert(typeof(myName));