Home > Web Front-end > JS Tutorial > What are the built-in objects in js?

What are the built-in objects in js?

百草
Release: 2023-11-09 13:44:03
Original
2033 people have browsed it

js built-in objects include Math, Date, String, Array, Object, Number, Boolean, RegExp, Function, Error, Error.prototype, Promise, Promise.prototype, Map, Set, WeakMap, WeakSet, Symbol, Proxy, Proxy.prototype and Reflect, etc.

What are the built-in objects in js?

The operating system for this tutorial: Windows 10 system, DELL G3 computer.

JavaScript has many built-in objects that provide developers with core functionality and foundation. Here are some of the main JavaScript built-in objects:

  • Math: Provides a set of static methods for performing common mathematical operations, such as Math.random() (generates a random number) , Math.floor() (rounding) and Math.sqrt() (square root), etc.

  • Date: used to process date and time. It can be used to create date objects, obtain date components (such as year, month, day, etc.), compare dates, calculate dates, etc. For example, new Date() creates an object that represents the current date and time.

  • String: used to process strings. Many methods are provided to operate strings, such as charAt() (get the character at a specific position), concat() (concatenate two or more strings), indexOf() (find the position of a specific string), etc.

  • Array: used to store multiple values ​​and provides many methods to operate these values, such as push() (add one or more elements to the end of the array), pop( ) (removes and returns the last element of the array), shift() (removes and returns the first element of the array), etc.

  • Object: All other JavaScript objects are derived from the Object object. The Object object itself mainly provides a method for mapping property names to values.

  • Number: used to process numbers. Many methods are provided to operate on numbers, such as parseInt() (parse a string into an integer), parseFloat() (parse a string into a floating point number), etc.

  • Boolean: There are two possible values: true and false, used for logical comparison and conditional judgment.

  • RegExp: used to process regular expressions. Provides many methods to operate regular expressions, such as test() (checking whether a string matches a certain pattern), etc.

  • Function: A function is a callable piece of code that receives parameters and may return a value. Functions can be nested within other functions or expressions, or passed as arguments to other functions or methods.

  • Error and Error.prototype: JavaScript provides an Error object for handling errors. The Error object has a message attribute that describes the error that occurred. In addition, JavaScript also provides several built-in error types, such as SyntaxError, TypeError, etc.

  • Promise and Promise.prototype: Promise is an asynchronous programming solution that provides a way to organize and manage the results of asynchronous operations. A Promise object represents the final completion (or failure) of an asynchronous operation and its result value.

  • Map, Set, WeakMap, WeakSet: These are new data structures introduced in ES6. Map objects hold key-value pairs and remember the original insertion order of keys. Set objects only store unique values, and the values ​​are automatically sorted in insertion order in the Set. WeakMap is similar to Map, but it allows keys to be of any type (including non-object types and circular references). WeakSet is similar to Set, but it allows to contain keys of any type (including unreachable objects).

  • Symbol: ES6 introduced the Symbol type, which represents a unique and immutable data type and is often used as the key value of an object or the key of a Map.

  • Proxy and Proxy.prototype: ES6 introduces the Proxy object, allowing you to define custom behaviors for basic operations. For example, you can use Proxy to define the reading behavior of an object, or to change the reading behavior of an object.

  • Reflect and Reflect.prototype: ES6 introduces the Reflect object and provides some static methods. Their behavior is similar to some methods of the original object, but they are not called directly on the original object. method.

The above are some of the main built-in objects of JavaScript. These built-in objects provide developers with the infrastructure to build complex applications.

The above is the detailed content of What are the built-in objects in js?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template