Home Web Front-end JS Tutorial JavaScript study notes (8) js built-in objects_basic knowledge

JavaScript study notes (8) js built-in objects_basic knowledge

May 16, 2016 pm 05:52 PM
built-in objects

1. URI methods

encodeURI() and encodeURIComponent() encode URI
encodeURI() will not encode special characters that are URIs themselves, such as colon, forward slash, hello, tic-tac-toe etc.
encodeURIComponent() will encode any non-standard characters

2.eval() method: interpret the code string in the parameter

Copy the code The code is as follows:

var msg = "hello world";
eval("alert(msg)"); //"hello world"


3.Math object
Math.E The value of e in mathematics
Math.PI The value of π
Math.SQRT2 The square root of 2
Math .abs(num) The absolute value of num
Math.exp(num) e raised to the num power
Math.log(num) The natural logarithm of num
Math.pow(num,n) num nth power
Math.sqrt(num) square root of num
Math.acos(x) arccosine of x
Math.asin(x) arcsine of x
Math.atan( x) Arctangent of x
Math.atan2(y,x) Arctangent of y/x
Math.cos(x) Cosine of x
Math.sin(x) Sine of x Value
Math.tan(x) Tangent value of x

4.min() and max() methods
Copy code The code is as follows:

var max = Math.max(3,45,67,32);
alert(max); //67
var min = Math.min(2,46,74);
alert(min); //2

5. Method of rounding decimals to integers
Math.ceil() round up Round
Math.floor() Round down
Math.round() Round
Copy code The code is as follows :

alert(Math.ceil(25.1)); //26
alert(Math.ceil(25.5)); //26
alert(Math.ceil(25.9) ); //26

alert(Math.round(25.1)); //25
alert(Math.round(25.5)); //26
alert(Math.round(25.9 )); //26

alert(Math.floor(25.1)); //25
alert(Math.floor(25.5)); //25
alert(Math.floor( 25.9)); //25

6. The random() method returns a random number between 0 and 1, excluding 0 and 1
Pick a random number within a certain range Formula:
Random number = Math.floor(Math.random * total first value) // Total number = second value - first value
Copy the code The code is as follows:

//Get a random number function within the range
function selectFrom(lowerValue,upperValue) {
var count = upperValue - lowerValue 1;
return Math.floor(Math.random() * count lowerValue);
}

var num = selectFrom(2,10);
alert(num); / /A number between 2 and 10 (including 2 and 10)
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
What are the built-in objects in Python? What are the built-in objects in Python? Nov 08, 2023 am 10:19 AM

There are ten types of Python built-in objects: "int", "float", "str", "list", "tuple", "dict", "set", "bool", "NoneType" and "function": 1. int , used to represent integer values; 2. float, used to represent real values; 3. str, used to represent text data; 4. list, used to store a series of ordered elements; 5. tuple, tuple type; 6 , dict, a data structure used to store key-value pairs, etc.

What are the built-in objects in asp? What are the built-in objects in asp? Nov 09, 2023 am 11:32 AM

ASP built-in objects include Request, Response, Session, Application, Server, Session.Contents, Application.Contents, Server.CreateObject, Server.MapPath, Server.Execute, Server.Transfer, etc. Detailed introduction: 1. Request: represents HTTP request object, etc.

Learn to use common PHP built-in objects: master the operation and usage of built-in objects Learn to use common PHP built-in objects: master the operation and usage of built-in objects Jan 10, 2024 am 10:02 AM

Master PHP built-in objects: Learn the operation and usage of commonly used built-in objects. Specific code examples are required. As a widely used back-end development language, PHP provides many powerful built-in objects that can help us develop and manage websites efficiently. Mastering the operation and usage of these built-in objects is crucial for PHP developers. This article will introduce some commonly used PHP built-in objects and provide specific code examples. 1. String processing object (String) String processing is often used in Web development, PHP

What are the built-in objects in nodejs? What are the built-in objects in nodejs? Nov 07, 2023 pm 03:33 PM

Nodejs built-in objects include Global, Process, Buffer, Console, Timer, EventEmitter, Stream, File System, HTTP, URL, Query String, Crypto, Path, OS, etc. Detailed introduction: 1. Global: global object, similar to the window object in the browser environment, which can be accessed anywhere; 2. Process, etc.

What are the built-in objects of Vue? What are the built-in objects of Vue? Nov 08, 2023 pm 04:52 PM

Vue's built-in objects include Vue, Vue instance, data, el, options, parent, root, children, slots, scopedSlots, refs, isServer, attrs and listeners. Vue.js is a progressive JavaScript framework for building user interfaces. In Vue.js, there are some built-in objects or global APIs that can be used to create and manage Vue applications.

What are the built-in objects of DOM? What are the built-in objects of DOM? Dec 19, 2023 pm 03:45 PM

dom内置对象有:1、document;2、window;3、navigator;4、location;5、history;6、screen;7、document.documentElement;8、document.body;9、document.head;10、document.title;11、document.cookie。

What are the commonly used built-in objects in js? What are the commonly used built-in objects in js? Nov 08, 2023 pm 01:44 PM

Commonly used built-in objects in js include "Object", "Function", "Array", "String", "Number", "​Boolean", "Date", "Math", "RegExp", "Error", "JSON" and "Global" 12 types: 1. Object, the parent object of all objects in js; 2. Function, function object; 3. Array, array object; 4. String: string object, etc.

What are built-in objects What are built-in objects Nov 13, 2023 am 10:40 AM

Built-in objects usually refer to objects with specific functions and properties provided by the programming language itself. These objects are usually part of the programming language and can be used directly in the code without additional import or loading. By using built-in objects, development Users can easily perform various operations, and these objects have the same behavior in different programs.

See all articles