GitHub 博客园 Nanakon

【众秒之门 JavaScript与jQuery技术精粹 #BOOK#】第4章 数据类型及定义

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title></title>
</head>
<body>
    <script>
        // NULL表示没有值,那么很明显它不能作为任何东西的实例
        console.log(typeof null) // object
        console.log(null instanceof Object) // false

        // NaN 即not a numbaer
        console.log(typeof NaN) // number
        console.log(NaN === NaN) // false

        // 空数组实际上等于true,但是在和布尔值比较时,却被看作false
        var someVar = []
        console.log(someVar == false)
        if (someVar) {
            console.log('hello')
        }

        // 正则表达式
        console.log('10 13 21 48 52'.replace(/\d+/g, '*'))
        console.log('10 13 21 48 52'.replace(/\d+/g, function(match) {
            return parseInt(match, 10) < 30 ? '*' : match
        }))
        console.log(/\w{3,}/.test('Hello'))
        function findWord(word, string) {
            var instancesOfWord = string.match(new RegExp('\\b' + word + '\\b', 'ig'))
            console.log(instancesOfWord)
        }
        findWord('car', 'Carl went to buy a car but had forgotten his credit card.')

        var animal = 'dog'
        function getAnimal(adjective) {
            console.log(adjective + ' ' + this.animal)
        }
        var myObj = {
            animal: 'camel'
        }
        getAnimal.call(myObj, 'lovely')

        var someVar = 'hello'
        setTimeout((function(someVar) {
            return function() {
                console.log(someVar)
            }
        })(someVar), 1000)
        someVar = 'goodbye'

        console.log(0.1 + 0.2)
    </script>
</body>
</html>

 

posted on 2013-09-20 08:05  jzm17173  阅读(214)  评论(0)    收藏  举报

导航

轻音