Published on: 05 June, 2013

Javascript Data Types

Posted by andy | 1310 views 2 likes 1 favourites 0 comments
Tumblr Digg Google Plus

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));
Comments

There are no comments available.

Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.
Related Articles
Published on: 20 June, 2016
Google Analytics is one of the best free analytics site tracker. It gives you an idea the statistic of your visitors like the country they come from, the URL or keyword they search to go to your site or even the demographic or ages of your visitors. If you are a developer, you definitely do not want to track any data when you are in development phase. In this tutorial, you will learn how to disable google analytics for local development by using a javascript code if condition.
Published on: 13 May, 2016
To convert a number value into money format in Javascript can be done easily using Javascript. Firstly you will need to use the built in toFixed function that will return a number value into two decimal point and then using a regular expression to reformat the value.