Javascript core objects: 1. Math object; 2. Number object; 2. Boolean object; 4. String object; 5. Array object; 6. Date object; 7. Object object; 8. Function object; 9. RegExp object.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
Core objects of javascript
1. Math object
The Math object is used to perform mathematics The operation does not use new to create an instance, but directly uses Math to directly call its properties and methods. For example
var pi_value=Math.PI var sprt_value=Math.sprt(16);
Properties | Description |
E | Returns the base e of natural numbers (approximately equal to 2.718) |
LN2 | Returns the natural logarithm of 2 (approximately equal to 0.693) |
LN10 | Returns the natural logarithm of 10 (approximately equal to 2.302) |
LOG2E | Returns the base 2 pair of e Number (approximately equal to 1.414) |
LOG10E | Returns the base 10 logarithm of e (approximately equal to 0.434) |
PI | Returns pi (approximately equal to 3.14159) |
SQRT1_2 | Returns the reciprocal of the square root of 2 (approximately equal to 0.707) |
SQRT2 | Returns the square root of 2 (approximately equal to 1.414) |
Method | Description |
abs(x) | Returns the absolute value of parameter x |
acos(x) | Returns the inverse cosine function of parameter x |
asin(x) | Returns parameter x The arcsine value of |
atan(x) | returns the parameter x as a value between -PI/2 and PI/2 radians The arcsine function |
atan2(y,x) | returns the angle from the x-axis to the point (x, y) (between -PI/2 and PI /2 radians) |
ceil(x) | Round up the parameter x. For example, the value of Math.ceil(2.3) is 3 |
cos(x) | Returns the cosine value of parameter x |
exp(x) | Returns the exponent of e |
floor | Round the parameters down. For example, the value of Math.ceil(2.3) is 2 |
Returns the natural logarithm of the parameter x (base is e) | |
Returns the two Maximum number | |
Returns the minimum of two numbers | |
Returns the y power of parameter x | |
Returns a random number between 0~1 | |
Round parameter x | |
Return the sine value of parameter x | |
Returns the square root of parameter x | |
Returns parameter Tangent |
2. Number object
var num1=new Nunber(value); var num2=Nunber(value); var num3=123;
Description | |
The maximum number that JavaScript can represent | |
JavaScript can represent the smallest number | |
non-numeric value | |
Represents negative infinity -Infinity, this value is returned when overflows | |
Represents positive infinity nfinity, this value is returned when overflows |
Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Convert the value into a string, use IRadix to specify the base, the default is decimal | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Convert the value into a character String, the number with x digits after the decimal place of the result | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
toExponential(x) | Convert the object value into exponential notation, the result There are numbers x after the decimal point|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Format the value into the length given by parameter | ##valueOf | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3、Boolean对象 var b=new Boolean(value); var b=false; 参数只有false、0、null、undefined的情况下会得到false的对象,否则会得到值为true Copy after login 4、String对象 var x=“JavaScript程序设计”; Copy after login
5、Array对象 (1)创建数组 var arrObj=new Array(); var arrObj=new Array(size); var arrObj=new Array(element0,element2); Copy after login (2)数组的length属性 (3)Array对象的方法
(4)二维数组的定义与访问 var citye=new Array(); citye[0]=new Array{"sha","上海","SHANGHAI","SH"}; citye[1]=new Array{"HYN","黄岩","HUANGYAN","HY"}; citye为二维数组,使用“数组变量名[子数组索引号][子数组中元素的索引号]”的格式来访问 遍历为双层循环遍历 Copy after login 6、Date对象 (1)Date对象的创建 var dateObj1=new Date(); var dateObj2=new Date(dateval); var dateObj3=new Date(year,month,date); Copy after login (2)Date对象的方法 var d3 =new Date("2019-12-12"); d3.getDate(); //获取当前日期中的日12 d3.getMonth(); //获取月份返回11,月份为(1-11) Copy after login 7、Object对象 (1)对象的创建 方式一: var cat1=new Object(); cat1.name="猫咪"; cat2.color="黄色"; cat.eat()=function(){ alert(this.name+"吃老鼠"); }; Copy after login 方式二: var cat1=new (); cat1.name="猫咪"; cat2.color="黄色"; cat.eat()=function(){ alert(this.name+"吃老鼠"); }; Copy after login 方式三: var cat1={ cat1.name="猫咪"; cat2.color="黄色"; cat.eat()=function(){ alert(this.name+"吃老鼠"); }; } Copy after login 创建对象实例 var cat2=Object.create(cat1); Copy after login 8、Function对象 (1)function的创建 funcation sum(x,y){ return (x+y); } Copy after login (2)第二种格式 function Cat(name,color){ cat1.name=name; cat2.color=color; cat.eat()=function(){ alert(this.name+"吃老鼠"); }; } var cat1= new Cat("猫咪","黄色"); cat1.eat(); Copy after login 9、RegExp对象 (1)创建RegExp对象 var regObj=new RegExp("pattern"[,flags]) var regObj=/pattern/{flags} Copy after login 其中pattern为必选,其对应正则表达式。参数flags是可选项。是标志组合常见的:g代表全局,i忽略大小写。m多行标志 pattern常用字符 (1)普通字符,如汉字、数字、字母 例如 /ab/ (2)转义字符 采用在前面加个\ (3)表达式 []、[^] (4)特殊字符 ^ $ (5)修饰匹配次数的特殊符号 {n} (2)RegExp对象的方法 (1)test方法 语法:reg.test(string); Copy after login
(2)exec方法 reg.exec(string); Copy after login exec:检索字符串是否存在reg表示模式,存在则返回被找到的值;否则返回空null 【相关推荐:javascript学习教程】 The above is the detailed content of What are the core objects of javascript. For more information, please follow other related articles on the PHP Chinese website!
Related labels:
source:php.cn
Previous article:What is the difference between javascript objects and arrays
Next article:What are JavaScript unit tests used for?
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
Latest Articles by Author
Latest Issues
Related Topics
More>
|