实例
<script> // while循环输出奇数 var arr = [1,2,3,4,5,6,7,8,9]; lenght = arr.length; var a = 0; while (a < lenght){ if (arr[a]%2!== 0) { console.log(arr[a]); } a++; } // 对象字面量 用花括号包裹起来 非法的属性名称可以用引号包裹起来 var b ={ name:'mate 20 x', battery:'5000', "sc-reen":'7.2', price:'5999', information:function () { console.log('手机名称:'+this.name+' 电池容量:'+this.battery+' 屏幕大小:'+this["sc-reen"]+' ***价格:'+this.price); } }; console.log(b.name); console.log(b.battery); console.log(b["sc-reen"]); console.log(b.price); console.log(b.name); b.information() // 函数表达式 计算三个数之和 var c = function (d,e,f) { return d+e+f; }; console.log('当前c的值为: '+c(5,8,9)); </script>
运行实例 »
点击 "运行实例" 按钮查看在线实例