GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.tutorialrepublic.com — Understanding the JavaScript Data Types - Tutorial Republic JAVASCRIPT BASIC
JS Introduction
JS Getting Started
JS Syntax
JS Variables
JS Generating Output
JS Data Types
JS Operators
JS Events
JS Strings
JS Numbers
JS If…Else
JS Switch…Case
JS Arrays
JS Sorting Arrays
JS Loops
JS Functions
JS Objects
JAVASCRIPT & DOM
JS DOM Nodes
JS DOM Selectors
JS DOM Styling
JS DOM Get Set Attributes
JS DOM Manipulation
JS DOM Navigation
JAVASCRIPT & BOM
JAVASCRIPT ADVANCED
JS Date and Time
JS Math Operations
JS Type Conversions
JS Event Listeners
JS Event Propagation
JS Borrowing Methods
JS Hoisting Behavior
JS Closures
JS Strict Mode
JS JSON Parsing
JS Error Handling
JS Regular Expressions
JS Form Validation
JS Cookies
JS AJAX Requests
JS ES6 Features
JAVASCRIPT EXAMPLES
JAVASCRIPT REFERENCE
Advertisements
JavaScript Data TypesIn this tutorial you will learn about the data types available in JavaScript. Data Types in JavaScriptData types basically specify what kind of data can be stored and manipulated within a program. There are six 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. The String Data TypeThe string data type is used to represent textual data (i.e. sequences of characters). Strings are created using single or double quotes surrounding one or more characters, as shown below: ExampleTry this code »
You can include quotes inside the string as long as they don't match the enclosing quotes. ExampleTry this code »
You will learn more about the strings in JavaScript strings chapter. The Number Data TypeThe number data type is used to represent positive or negative numbers with or without decimal place, or numbers written using exponential notation e.g. 1.5e-4 (equivalent to 1.5x10-4). ExampleTry this code »
The Number data type also includes some special values which are: ExampleTry this code »
While ExampleTry this code »
You will learn more about the numbers in JavaScript numbers chapter. The Boolean Data TypeThe Boolean data type can hold only two values: ExampleTry this code »
Boolean values also come as a result of comparisons in a program. The following example compares two variables and shows the result in an alert dialog box: ExampleTry this code »
You will learn more about the comparisons in JavaScript if/else chapter. The Undefined Data TypeThe undefined data type can only have one value-the special value ExampleTry this code »
The Null Data TypeThis is another special data type that can have only one value-the A variable can be explicitly emptied of its current contents by assigning it the ExampleTry this code »
The Object Data TypeThe An object contains properties, defined as a key-value pair. A property key (name) is always a string, but the value can be any data type, like strings, numbers, booleans, or complex data types like arrays, function and other objects. You'll learn more about objects in upcoming chapters. The following example will show you the simplest way to create an object in JavaScript. ExampleTry this code »
You can omit the quotes around property name if the name is a valid JavaScript name. That means quotes are required around ExampleTry this code »
You will learn more about the objects in JavaScript objects chapter. The Array Data TypeAn array is a type of object used for storing multiple values in single variable. Each value (also called an element) in an array has a numeric position, known as its index, and it may contain data of any data type-numbers, strings, booleans, functions, objects, and even other arrays. The array index starts from 0, so that the first array element is The simplest way to create an array is by specifying the array elements as a comma-separated list enclosed by square brackets, as shown in the example below: ExampleTry this code »
You will learn more about the arrays in JavaScript arrays chapter. The Function Data TypeThe function is callable object that executes a block of code. Since functions are objects, so it is possible to assign them to variables, as shown in the example below: ExampleTry this code »
In fact, functions can be used at any place any other value can be used. Functions can be stored in variables, objects, and arrays. Functions can be passed as arguments to other functions, and functions can be returned from functions. Consider the following function: ExampleTry this code »
You will learn more about the functions in JavaScript functions chapter. The typeof OperatorThe The ExampleTry this code »
As you can clearly see in the above example when we test the This is a long-standing bug in JavaScript, but since lots of codes on the web written around this behavior, and thus fixing it would create a lot more problem, so idea of fixing this issue was rejected by the committee that design and maintains JavaScript. Advertisements
Advertisements
|
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |