JavaScript-11种内置对象

1.字符串对象

var str1="hello"

var str2=new String("hello")

2.数组对象

var arr1 = [1,"hello",[11,2],{"name":"lee"}]

var arr2 = new Array(5)  #5不是内容是size

var arr3 = new Array(1,"world",true,[123])

3.函数的创建

方式一:

function foo(name) {

console.log("hello"+name)

}

方式二:

var bar = new Function("name","console.log(\"hello\"+name)")

-----------------------------------

面试题:

function f(x,y) {

return x+y

}

var f=1; var b=2;

f(f,b);

#结果报错:f is not a function(同python)

--------------------------------------------

接收n个参数,返回和:

function add() {

var sum=0

for(var i=0;i<arguments.length;i++) {

sum+=arguments[i]

}

return sum

}

-----------------------------------------

匿名函数一:

var func=function(arg) {

alert(arg)

}

func("hello");

匿名函数二(自执行函数):

(function(arg) {

alert(arg)

})("hello")

posted @ 2018-06-18 21:18  benchdog  阅读(533)  评论(0编辑  收藏  举报