JavaScript learns the JS data types, coercion type conversions, and object properties

Source: Internet
Author: User

JavaScript learns the JS data types, coercion type conversions, and object Properties

JavaScript data Types

There are five primitive data types in javascript:Undefined, Null, Boolean, number, and string.

  The Undefined data type has only one value:Undefined.

In JavaScript, if the function does not declare a return value, it returns undefined. (There are instances later).

If typeof is followed by an undefined parameter, it is also returned undefined.

  The value of the null data type is only one:null.

  Null relationship to undefined: undefined is actually derived from null.

So:

NULL);

The bullet box displays true.

  The boolean data type has a value of two: true and false.  

declares a Boolean value of False

String type , either single or double quotation marks.

there is no char data type in JavaScript.

typeof operator

  typeof is a unary operator followed by the name of a variable that gets the data type of the variable, with a return value of 5:undefined, Boolean,number, String and Object.

  S is the original type  alert (// output: string  

  Another way:

S is the object type alert (// Output: Object  

  The base class of an object type is Object (much like Java), so typeof determines that the object type is no longer specific to what type of object it is.

False; alert (//var s = 3; alert (// output      number

case where function has no return value

In JavaScript, If the function does not declare a return value, it returns undefined.

  function Add ()  {       return;  or simply do not write return// bullet box display undefined     

Forcing type conversions

Coercion type conversions: There are 3 types of forced type conversions in javascript:

  Boolean (value), number (value), String (value).

More general:

var s = number (3); alert (s);

Convert to a Boolean value:

var s = Boolean ("Hello"// display true 

var s = String ("Hello");  // Note there is no keyword new, which indicates coercion type conversion alert (typeof s);  output string// If you add new, the object is output      

Note: The coercion type conversion is preceded by the new keyword.

properties of the object

In JavaScript, all objects are inherited from object objects.

The property in object is not enumerable (propertyisenumerable returns false), so it cannot be

The properties are obtained through the for...in statement.

New Object ();  For (in object) {alert (v);} // no bullet box because there is no enumerable attribute alert (object.propertyisenumerable ("Prototype"));  returns false        

 

Dynamic management Properties

In JavaScript, you can dynamically add properties to an object, or you can dynamically delete an object's properties.

var object = new object ( ); alert (object.username); //undefined// add attribute object["username" = "Shengsiyuan" ; object.username= "Shengsiyuan";//two ways to dynamically add properties Usernamealert (Object.username); Span style= "color: #008000;" >// Displays the Name property defined // Delete properties delete object.username; ////undefined           

Another way to define an object:

To define an object as a property:

The most common way to define objects in JavaScript is var object = {username: "Zhangsan", password:123};alert (object.username); alert (Object.password);  

References

Santhiya Garden Zhang Long teacher Java web video tutorial.

W3school JavaScript Tutorial: http://www.w3school.com.cn/js/index.asp

English version: http://www.w3schools.com/js/default.asp

JavaScript learns the JS data types, coercion type conversions, and object properties

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.