js语法笔记

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body style="background: rgba(199,237,204,1)">


<pre id="container">

</pre>
<pre>
















</pre>
</body>
<script type="text/javascript">


    function print(txt) {
        document.getElementById("container").innerHTML += ('\n') + txt;
    }

    document.body.onclick = function () {
        window.location.reload()
    }
    console.log = print;
    console.log("hello")

    console.log(Number.MAX_VALUE + 1e300)

    console.log(Number.POSITIVE_INFINITY - 1e307);

    console.log(Number.MAX_VALUE == Number.POSITIVE_INFINITY);

    //    if ("" == false) {
    //        alert("bu存在")
    //    } else {
    //        alert(" 存在")
    //    }

    console.log(parseInt("   0123  .x xx   "))


    var obj = {
        name: null
    }

    if (obj.name) {
        console.log("yes")
    } else {
        console.log("no")
    }

    if (obj.hasOwnProperty("name")) {
        console.log("has name")
    } else {
        console.log("no has name")
    }


    console.log("[] instanceof Array  " + ( {} instanceof Array))

    console.log("-----------")

    var arr = ["a", "b"];

    console.log(arr)

    console.log(arr[0])

    console.log(arr[1])
    console.log(arr[2])

    arr.length = 3;
    console.log("-----------")

    console.log(arr)

    console.log(arr[0])

    console.log(arr[1])
    console.log(arr[2])

    for (var i in ["a", "b"]) {
        console.log(">> " + i)
    }
    console.log(">>>> i " + i)

    var list = [];
    list.push("a", "b", "c");
    console.log("push: " + list.join("|"))

    console.log(list.pop())
    console.log(list.shift())

    list = ["a", 'b', "c", ['d', 'e', ['f', 'g', ['h', ['i']]]], 'j'];
    print(">>>>>>" + list.length + " :::: " + list.join('|'))


    list = ["a", 'b', "c", 'd', 'e', 'f', 'g'];
    print("......." + list.length + " ::  " + list.join("|"))
    list.unshift("1")
    console.log(list)
    list.shift();
    print(list.reverse())


    print("-----sort-------")
    print(list.sort())
    print(list.sort(function (a1, a2) {
        return a2 - a1
    }))
    print(list.sort(function (a1, a2) {
        return a1 - a2
    }))

    print(list.concat(["xxx", ["fff", ["eee"]]]))

    print(list.slice(2, 4))
    print('---list------');
    print(list.join('|'));
    print('..........')
    print(list.slice(1, 5));
    print(list.slice(-3))
    print(list.slice(-4))
    print(list.slice(-7))
    print(list.slice(-8))
    print(list.slice(-10))


    print('*************')
    print(list);
    print(list.splice(0, 3, 'x', 'xx'));
    print(list.join('|'));

    print(list.indexOf('xx'))

    print("--------- list=['a','b','c','d','e','f'] -------");
    list = ['a', 'b', 'c', 'd', 'e', 'f']
    for (item  of list) {
        print(item)
    }

    list.forEach(function (p1, p2) {
        print(p1 + "  " + p2 + "  ")
    })
    print('@@@@@@@@')
    var res = list.reduce(function (p1, p2, p3, p4) {
        print(p1 + "  " + p2 + "  " + p3 + "   " + p4)
        return p1 + p2
    })

    print(res)

    res = list.reduceRight(function (p1, p2, p3, p4) {
        print(p1 + "  " + p2 + "  " + p3 + "   " + p4)
        return p1 + p2
    })
    print(res)

    print(Date.now())
    print(new Date(2017,5,6,7,8,9).toLocaleString())
    print(new Date().getFullYear())
</script>


</html>




输出



hello
Infinity
Infinity
false
123
no
has name
[] instanceof Array  false
-----------
a,b
a
b
undefined
-----------
a,b,
a
b
undefined
>> 0
>> 1
>>>> i 1
push: a|b|c
c
a
>>>>>>5 :::: a|b|c|d,e,f,g,h,i|j
.......7 ::  a|b|c|d|e|f|g
1,a,b,c,d,e,f,g
g,f,e,d,c,b,a
-----sort-------
a,b,c,d,e,f,g
g,f,e,d,c,b,a
a,b,c,d,e,f,g
a,b,c,d,e,f,g,xxx,fff,eee
c,d
---list------
a|b|c|d|e|f|g
..........
b,c,d,e
e,f,g
d,e,f,g
a,b,c,d,e,f,g
a,b,c,d,e,f,g
a,b,c,d,e,f,g
*************
a,b,c,d,e,f,g
a,b,c
x|xx|d|e|f|g
1
--------- list=['a','b','c','d','e','f'] -------
a
b
c
d
e
f
a  0  
b  1  
c  2  
d  3  
e  4  
f  5  
@@@@@@@@
a  b  1   a,b,c,d,e,f
ab  c  2   a,b,c,d,e,f
abc  d  3   a,b,c,d,e,f
abcd  e  4   a,b,c,d,e,f
abcde  f  5   a,b,c,d,e,f
abcdef
f  e  4   a,b,c,d,e,f
fe  d  3   a,b,c,d,e,f
fed  c  2   a,b,c,d,e,f
fedc  b  1   a,b,c,d,e,f
fedcb  a  0   a,b,c,d,e,f
fedcba
1493892953890
2017/6/6 上午7:08:09
2017




















  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值