码迷,mamicode.com
首页 > 编程语言 > 详细

字符串、数组对象创建方式、函数创建、arguments数组

时间:2018-06-18 17:08:04      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:turn   对象   color   输入   length   ret   div   name   字符串   

    //创建字符串对象两种方式
    var str1="hello";
    var str2=new String("hello2")
var str1="hello";
    console.log(str1.length)//字符串的属性
var arr=[a,123,{name:we},3]
    var arr2=new Array(wer)
 //函数创建方式1,较好
    function f(x,y) {
        alert(123);
        return x+y;

    }
    console.log(f(1,3))
第二种不合适
<script> function f(name) { console.log("hello"+name) } var obj=new Function(name,console.log(\"hello\"+name)) obj(jerry) </script>
//函数调用多了也是只取前几个
<script>
 function add(x,y,z) {
     return x+y+z;
 }
 console.log(add(1,2,3,4,5,6))
</script>
<script>//函数有return,
     function add() {//arguments存储输入的数值,无论多少都会存放在arguments数组内
         var sum=0;
         for(var i=0;i<arguments.length;i++){
             sum+=arguments[i];
             
         }
            return sum;
     }
     console.log(add(1,2,3,4,5))
     console.log(add(1,2))
</script>

 

字符串、数组对象创建方式、函数创建、arguments数组

标签:turn   对象   color   输入   length   ret   div   name   字符串   

原文地址:https://www.cnblogs.com/wfl9310/p/9195409.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!