JavaScript Tutorial

JS HomeJS EditorsJS How toJS Basic ProgramJS ConsoleJS VariableJS constJS Data TypesJS StringJS Type CastingJS KeywordsJS OperatorsJS Use StrictJS Escape SequencesJS Comments

JS Control Statements

JS ifJS if elseJS else ifJS BreakJS ContinueJS Switch Case

JS Looping

JS Loop ForJS Loop For InJS Loop WhileJS Loop Do While

JS Array

JS ArrayJS Array One DimensionalJS Array Multi DimensionalJS Array Associative

JS Functions

JS FunctionJS Function SelfJS Function call()JS Function apply()JS Call By ValueJS Call By ReferenceJS Function Closures

JS Scope

JS Scope GlobalJS Scope LocalJS Let

JS File Handling

JS File Handling

JS Error Handling

JS try catchJS throwJS finally

JS Select Particulars

JS getElementByID()JS getElementsByClassName()JS getElementsByTagName()JS getElementsByName()JS querySelector()JS querySelectorAll()

JS Popup

JS alert()JS confirm()JS prompt()

JS Events

JS EventsJS Media EventsJS Mouse EventsJS Keyboard EventsJS Form EventsJS Drag EventsJS Clipboard EventsJS Print EventsJS Animation EventsJS Transition EventsJS Server-Sent EventsJS Touch EventsJS Object Events

JS Methods

JS Array MethodsJS String MethodsJS Math MethodsJS Number MethodsJS Date MethodsJS Element MethodsJS Window MethodsJS Node MethodsJS Document MethodsJS Console MethodsJS Timing MethodsJS Navigator MethodsJS Miscellaneous Methods

JS Properties

JS Array PropertiesJS String PropertiesJS Number PropertiesJS MouseEvent PropertiesJS KeyboardEvent PropertiesJS AnimationEvent PropertiesJS TransitionEvent PropertiesJS Element PropertiesJS Window PropertiesJS Node PropertiesJS Document PropertiesJS Navigator PropertiesJS HashChangeEvent PropertiesJS Miscellaneous Properties

JS Regular Expressions

JS Regexp

JS Cookies

JS Cookies

JS Interview Programs

JS Common ProgramsJS Array ProgramsJS Converter ProgramsJS Star Patterns ProgramJS Number Patterns ProgramJS Alphabet Patterns Program

JS Reference

LEARN JSONLEARN AJAXJS KeycodeMIME TypesASCII Table

JavaScript Data Types

Last Updated:

JavaScript Data Types

Data can come in many different forms, or types that enable you to use data effectively in your code.

JavaScript supports four different types of Data, they are

  • String
  • Number
  • Boolean
  • Object (including Array, Date, etc)

Note: String, Number, and Boolean are primitive types. Whereas, Object is a non-primitive types.

String

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> var name = "OSx"; var model = "version 14.2"; document.write("We are using "+name+" "+model); //Using quotation var uSingleQuotation = "I'm here"; var uDoubleQuotation = 'I like "JavaScript".'; document.write("<br>"+uSingleQuotation+" and "+uDoubleQuotation); </script> </body> </html>

Number

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> //Integer value var x = 1; //Floating point value var y = 2.5; var z = x + y; document.write("z = "+z); </script> </body> </html>

Object

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> //Number only var x = [1, 2, 3]; //String only var y = ["One", "Two", "Three"]; //Number and string var z = [1, "Two", 3]; document.write("Array 1 = "+x[0]+", "+x[1]+", "+x[2]); document.write("<br>Array 2 = "+y[0]+", "+y[1]+", "+y[2]); document.write("<br>Array 3 = "+z[0]+", "+z[1]+", "+z[2]); </script> </body> </html>

Using typeof Operator

Use typeof operator to find the data type of a variable.

You will learn more about JavaScript object in our JSON Tutorial

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p>Check your Console</p> <script> var str = "Hello"; var num = 1; var married = false; var arr = ["apple", "mangle"]; var obj = { company: "Honda", model: "CBR 1000RR", color: "Red" } console.log("str = " +typeof str); console.log("num = " +typeof num); console.log("married = " +typeof married); console.log("arr = " +typeof arr); console.log("obj = " +typeof obj); </script> </body> </html>

Share this Page

Meet the Author