Introduction to JavaScript built-in objects

Source: Internet
Author: User
ArticleDirectory
    • Introduction to JavaScript objects
    • Javascript string object
    • Javascript date object
    • Javascript array object
    • Javascript Boolean (logical) object
    • Javascript math (arithmetic) object
    • Javascript Regexp object
    • Javascript Global Object
Introduction to JavaScript objects

Javascript is object-orientedProgramming Language(OOP ). The OOP language enables us to customize object and variable types. (In fact, it is only object-based and does not fully possess the three major features of object-oriented languages [encapsulation, inheritance, and polymorphism]).

Object-Oriented Programming

The advanced JavaScript section describes how to create your own objects. Now, we start to learn about built-in JavaScript objects and how to use them. Object is only a special type of data. The object has attributes and methods.

 

Javascript string object

A string is a basic data type of JavaScript. It should be noted that JavaScript strings are immutable, and the methods defined by the string class cannot change the content of strings. A method like string. touppercase () returns a brand new string instead of modifying the original string.

The Length attribute of the string object declares the number of characters in the string.

The string class defines a large number of methods to operate on strings. It is generally divided into the following types: Search for substrings, intercept, split and splice strings, match regular expressions, and change string styles.

 

Javascript date object

The date object is used to process the date and time. The date object automatically saves the current date and time as its initial value.

Most methods of date objects are as follows:

Getxxx: Get year, month, day, hour, minute, second, and so on.

Setxxx: Set year, month, day, hour, minute, second, and so on.

Toxxxstring: convert to a string of a certain format.

 

Javascript array object

An array object uses a separate variable name to store a series of values.

The common attribute of an array is length, which represents the number of elements in the array.

Commonly used methods of arrays include sorting, adding and deleting elements, splicing another array, and converting to a string. The methods for adding and removing elements also simulate the data structure of stacks or queues.

 

Javascript Boolean (logical) object

A boolean (logical) object is used to convert non-logical values to logical values (true or false ).

In JavaScript, a Boolean value is a basic data type. A boolean object is a Boolean object that packs a Boolean value. A boolean object is mainly used to convert a Boolean value to a string's tostring () method. When the tostring () method is called to convert a Boolean value to a string (usually called implicitly by JavaScript), JavaScript internally converts the Boolean value to a temporary Boolean object, then, call the tostring () method of this object.

 

Javascript math (arithmetic) object

Math (arithmetic) objects are used to execute common arithmetic tasks.

Math objects are not classes of objects like date and string, so there is no constructor math (). functions like math. Sin () are just functions, not methods of an object. You can call all attributes and methods of a math object without creating it. (Equivalent to static classes and static methods)

The common attributes of a math object are mathematical-related constant attributes, such as the circumference rate π, the square root of 2, and the arithmetic constant E (the base number of the natural logarithm, approximately 2.718 ).

The most common methods of math objects are as follows: rounded up (down) to an integer, rounded to an integer, random number, and return a large number or decimal number of two numbers.

 

Javascript Regexp object

What is Regexp?

Regexp is the abbreviation of a regular expression. When you retrieve a text, you can use a mode to describe the content to be retrieved. Regexp is in this mode. A simple mode can be a single character. More complex modes include more characters and can be used for parsing, format check, replacement, and so on. You can specify the search position in the string and the type of characters to be retrieved.

This knowledge point is relatively complicated. It takes some time to master it. For details, see the JS manual.

 

Javascript Global Object

This is an inherent object that aims to centralize all global methods in one object.GlobalThe object cannot be used.NewCreate an operator. It is created when the scripting engine is initialized and made available even if its method and attributes are available.

Attribute: infinity attribute | Nan attribute

Method: escape method | eval method | isfinite method | isnan method | parsefloat method | parseint method | Unescape Method

 

What can JavaScript do?

Javascript can verify the integrity of form data, and combine Dom, BOM, Ajax, CSS and other necessary Web Front-end technologies to make a very powerful dynamic web page.

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.