Detail JavaScript data types and conversions

Source: Internet
Author: User
Tags javascript array

Detail JavaScript data types and conversions

JavaScript data types

1.Boolean (BOOL)

Boolean: (value type) var b1=true;//boolean type

2.Number (digital)

Value: (value type) var n1=3.1415926;//numeric type

N1.tofixed (3);//rounding retains 3 decimal places.

3.String (String)

var s1= ' hello ';//String type


String: (value type, string immutable attribute)
4.Undefined (not defined)

Undefined is a value type, and the result computed with other values is not what we want, but slightly different from the null in the database, such as with numeric calculations or with string calculations.

The undefined type, the null type, are data types with only one value, undefined and null, respectively.

5.Null (Empty object)

6.Object (Object type)

object is a reference type, and the others are basic data types.

String is also a base type and cannot be added to a dynamic property, while a reference type is available.

A reference type Object instanceof type that determines whether a value is a type, all reference types Instanceof object returns are true

7. Application Type

Objects (object): (reference type)

var tim=new Date ();//object Type (object) var names=[' Zs ', ' ls ', ' ww '];//array is also object type (object) var obj=null;//object


Function: (reference type)

function Fun () {}//typeof (fun);//output result is function, type


PS: View variable type with typeof (variable), reference: http://www.lai18.com/content/350151.html

Null and undefined in JavaScript

Undefined, which indicates an unknown state

If the variable is declared but not initialized, the value of the variable is an unknown state (undefined). The return value is a undefined when there is no explicit return value (access to a nonexistent property or an object Window.xxx) method. When the typeof operator is applied to an undeclared variable, it is displayed as undefined (*)

Null represents an object that does not already exist, and Null is a value that has a special meaning.

A variable can be assigned a value of NULL, when the value of the variable is "known state" (not undefined), or null. (Used to initialize variables, clear variable contents, free memory)

Undefined==null//The result is true, but the meaning is different.

Undefined===null//false (*), PS: First determine whether the type is consistent, and then determine the value. = = = Strictly equal To,!== strictly not equal to

because = = Converts a value to a type and then determines whether it is equal, sometimes with unexpected results, it is recommended to use = = =. But note that there are cases where using = = can bring better results.

Type conversions

parseint (ARG) converts the specified string, converted to an integer parsefloat (ARG), to the specified string, converted to a floating-point number (ARG), to convert the given value (any type) to a digit (which can be an integer or a floating point), and to convert the entire value, not the partial value. If the string cannot be fully converted to an integral type, Nan is returned. (not a number) IsNaN (ARG), determines whether ARG is a non-numeric (Nan), and Nan is not equal to Nan. String (ARG) converts the given value (any type) to a string; Boolean (ARG) converts the given value (any type) to a Boolean type; (*) eval (codestring) computes and executes a string of JS code.


The above is the JavaScript data type and conversion method, I hope you can like.


Extended Reading

"Talking about JavaScript series" series of technical Articles to organize collection  

1 on the simulation of object-oriented technology in JavaScript

2 talking about JavaScript function hijacking [transfer from Xfocus] 1th/3 page

3 on JavaScript Object-oriented programming

4 old fish on JavaScript object-oriented programming

5 talking about the data type detection of JavaScript

6 on JavaScript nesting functions and closures

7 based on a piece of code talk about JavaScript closures

8 on coding specification of JavaScript programming language

9 on JavaScript Object-oriented programming

10 on JavaScript functions and stacks

11 Talking about scopes in JavaScript

12 several ways to deal with JavaScript event handlers

13 about JavaScript mouse and wheel events

14 on JavaScript Event simulation

15 on the prototype inheritance of JavaScript

16 talking about the event binding of JavaScript

17 on the modification of JavaScript function parameters

18 on JavaScript execution order

19 on JavaScript six data types and special points of attention

20 talking about JavaScript character set

21 talking about the difference between a var declaration and a variable defined in JavaScript

22 on JavaScript Framework Classification

23 talking about deep copying in JavaScript

24 talking about createelement events in JavaScript

25 talking about JavaScript callback function

26 on JavaScript function throttling

27 on JavaScript implementation of object-oriented classes

28 talking about the efficiency of JavaScript execution

29 on the scope of JavaScript variables

30 talking about the stop condition of uniform motion in JavaScript

31 on how JavaScript implements uniform motion

32 on JavaScript object model and function object

33 on JavaScript Base64 encryption and decryption

34 on the types of JavaScript function functions

35 about JavaScript date and time objects

36 talking about the JavaScript array object

37 talking about strings and arrays in JavaScript

38 on JavaScript iterative method

39 on JavaScript Merging method

40 on JavaScript Object-oriented programming

41 on JavaScript function properties and methods

42 talking about the internal properties of JavaScript functions

43 about JavaScript math and number objects

44 talking about function and object in JavaScript

45 talking about the debugging of JavaScript

46 on JavaScript arrays and dictionaries

47 talking about custom templates in JavaScript

48 talking about the date object in JavaScript, the Math object

49 on the application of this in JavaScript

50 on common methods of string objects in JavaScript

51 Talking about JavaScript events

52 talking about the instanceof and typeof in JavaScript

53 on JavaScript data types and conversions

54 A brief introduction to the properties list of JavaScript events

55 talking about JavaScript data types

56 on the eight sorts of JavaScript implementation

57 on JavaScript syntax and timing functions

58 talking about the static properties and prototype properties of JavaScript

59 talking about the use of the semicolon in JavaScript

60 talking about closures in JavaScript

61 talking about JavaScript event cancellation and blocking bubbling

62 talking about JavaScript strings and arrays

63 Elementary Introduction to basic packaging types in JavaScript

64 talking about the use of the Math.atan () method in JavaScript



Extended Reading


Detail JavaScript data types and conversions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.