JavaScript中的类型、值和变量练习题

JavaScript everyinch 3613℃ 0评论

一、单选题

  • 1.关于JavaScript中数字表述错误的是( )
    A. 并不区别整型数值和浮点型数值
    B. 所有的数字都是由浮点型表示的
    C. JavaScript中的数字表示都是非常精确的
    D. 采用IEEE 754标准定义的64位浮点格式表示数字
    C
  • 2.以下哪个常量值最大?
    A.80
    B. 0X65
    C.095
    D.0115
    B
  • 3.浮点型直接量6.02e23表示( )
    A. 6.02 x 23
    B. 6.02 x 1023
    C. 6.02 x 223
    D. 6.02 x 1623
    B
  • 4.Math对象的方法,Math.pow(2,53)表示( )
    A. 2 x 53
    B. 53 / 2
    C. 253
    D. 2*1053
    C
  • 5.Math.exp(3)表示( )
    A. 3
    B. 23
    B. 3*103
    D. Math.E 的3次幂
    D
  • 6.下面哪一条语句在页面上显示圆周率π( )
    A. document.write(Math.Pi)
    B. document.write(Math.pi)
    C. document.write(Math.PI)
    D. document.write(Date.Pi)
    C
  • 7.以下哪种表达式产生一个0-7之间的随机整数?( )
    A. Math.floor(Math.random()*6)
    B. Math.floor(Math.random()*7)
    C. Math.floor(Math.random()*8)
    D. Math.sqrt(Math.random())
    B
  • 8.下面程序的输出为:
    var total=16.5;
    var number = sum(5.50 , 5.01 , 5.99);
    alert(total);
    function sum(n1 , n2 , n3) {
    total = Math.round(n1) + Math.ceil(n2) + Math.floor(n3);
    return total;
    }
    A. 15
    B. 16
    C. 17
    D. 18
    C
  • 9.数学运算1/0的结果是( )
    A. 0
    B. 报错
    C. Infinity
    D. NaN
    C
  • 10.数学运算-1/0的结果是( )
    A. -Infinity
    B. 报错
    C. -0
    D. NaN
    A
  • 11.数学运算Number.MAX_VALUE+1的结果是( )
    A. undefined
    B. 报错
    C. Infinity
    D. NaN
    C
  • 12.数学运算0/0的结果是( )
    A. undefined
    B. 报错
    C. Infinity
    D. NaN
    D
  • 13.数学运算Number.MIN_VALUE/2的结果是( )
    A. 0
    B. –Infinity
    C. NaN
    D. 下溢
    A
  • 14.如果有变量:
    var zero = 0;
    var negz = -0;
    则下面的结果是( )
    zero === negz;
    1/zero === 1/negz;
    A. true true
    B. true false
    C. false false
    D. false true
    B
  • 15.有代码var x = 0.3 – 0.2; 则x == 0.1的结果是( )
    A. false
    B. true
    C. 0
    D. undefined
    A
  • 16.下面不是Date对象的方法是( )
    A. getYear
    B. getMonth
    C. getWeek
    D. getDate
    C
  • 17.以下哪种语句把日期对象rightnow的星期号赋给变量weekday?( )
    A. var weekday = rightnow.getDate();
    B. var weekday = rightnow.getDay();
    C. var weekday = rightnow.getWeek();
    D. var weekday = rightnow.getWeekday();
    B
  • 18.下面哪一个字符串变量定义语句是不正确的?
    A. var mytext = “Here is some text!”
    B. var mytext = ‘Here is some text!’
    C. var mytext = ‘Here is some text!”
    D. var mytext = “Here is\nsome text!”
    C
  • 19.下面四个JavaScript语句中,哪一个是合法的?
    A. document.write(”John said ,”Hi!””)
    B. document.write(”John said ,”Hi!”‘)
    C. document.write(”John said ,”Hi!”)
    D. document.write(”John said ,\”Hi!\””)
    D
  • 20.表示退格符的转义序列是( )
    A. \t
    B. \b
    C. \r
    D. \f
    B
  • 21.分析下面的JavaScript代码:x=11; y=’number’; m = x+y; m的值为多少?
    A. NaN
    B. 11
    C. ’11number’
    D. ’11’
    C
  • 22.在JavaScript中,连接字符串的符号是( )
    A. .(点号)
    B. +(加号)
    B. /(斜杆)
    D. -(减号)
    B
  • 23.有代码var s = “hello, world”; s.charAt(s.length-1)表示的是( )
    A. h
    B. d
    C. ”
    D. 空白
    B
  • 24.以下哪个String对象的方法得到指定位置处的字符?( )
    A. indexOf()
    B. charAt()
    C. charIsAt()
    D. indexOfThePosition()
    B
  • 25.在JavaScript中,String对象的方法不包括( )
    A. charAt()
    B. substring()
    C. toUpperCase()
    D. length()
    D
  • 26.如果有字符串:var stringValue = “hello world”; stringValue.slice(3)返回( )
    A. lo world
    B. hel
    B. llo world
    D. rld
    A
  • 27.如果有字符串:var stringValue = “hello world”; stringValue. substring(3)返回( )
    A.rld
    B. hel
    B. lo world
    D. lo world
    D
  • 28.如果有字符串:var stringValue = “hello world”; stringValue. substr(3)返回( )
    A. wor
    B. hel
    C. lo world
    D. rld
    C
  • 29.如果有字符串:var stringValue = “hello world”; stringValue. slice(3,7)返回( )
    A. o wo
    B. llo worl
    C. lo world
    D. lo w
    D
  • 30.如果有字符串:var stringValue = “hello world”; stringValue. substring(3,7)返回( )
    A. o wo
    B. llo worl
    C. lo world
    D. lo w
    D
  • 31.如果有字符串:var stringValue = “hello world”; stringValue. substr(3,7)返回( )
    A. o wo
    B. lo worl
    C. lo world
    D. lo w
    B
  • 32.如果有字符串:var stringValue = “hello world”; stringValue.slice(-3)返回( )
    A. lo w
    B. hel
    B. lo world
    D. rld
    D
  • 33.如果有字符串:var stringValue = “hello world”; stringValue. substring(-3)返回( )
    A.rld
    B. hel
    B. lo world
    D. hello world
    D
  • 34.如果有字符串:var stringValue = “hello world”; stringValue. substr(-3)返回( )
    A. lo w
    B. hel
    C. rld
    D. lo world
    C
  • 35.如果有字符串:var stringValue = “hello world”; stringValue.slice(3,-4)返回( )
    A. lo w
    B. hel
    B. lo world
    D. rld
    A
  • 36.如果有字符串:var stringValue = “hello world”; stringValue. substring(3,-4)返回( )
    A.rld
    B. hel
    C. lo world
    D. hello world
    B
  • 37.如果有字符串:var stringValue = “hello world”; stringValue. substr(3,-4)返回( )
    A. lo w
    B. 空字符串
    C. rld
    D. lo world
    B
  • 38.任意JavaScript的值都可以转换为布尔值。下面的哪个值不会被转换成false( )
    A. undefined
    B. null
    C. “ ”
    D. NaN
    C
  • 39.对null执行typeof预算,返回( )
    A. Null
    B. “Object”
    C. “Null”
    D. “{}”
    B
  • 40.下面不是全局属性的选项是( )
    A. undefined
    B. Infinity
    C. Math
    D. NaN
    C
  • 41.下面不是全局函数的选项是( )
    A. isNaN()
    B. parseInt()
    C. eval()
    D. write()
    D
  • 42.下面不是构造函数的选项是( )
    A. Date
    B. String
    C. Math
    D. Object
    C
  • 43.下面的代码:var s = “hello”; s.toUpperCase(); 输出s的值是( )
    A. “HELLO”
    B. “hello”
    C. “Hello”
    D. “”空字符串
    B
  • 44.有对象var o = {x:1}, p = {x:1}; o === p的结果是( )
    A. true
    B. false
    C. 0
    D. NaN
    B
  • 45.有代码var a = []; var b = a; a === b的结果是( )
    A. true
    B. false
    C. 0
    D. NaN
    A
  • 46.10 + ” object” 的结果是( )
    A. 10
    B. NaN
    C. “10 objects”
    D. 10 NaN
    C
  • 47.”7″ * “4” 的结果是( )
    A. “74”
    B. 28
    C. “28”
    D. “7*4”
    B
  • 48.var n = 1 – “x”; n的值是( )
    A. 1-x
    B. 1
    C. NaN
    D. “1-x”
    C
  • 49.var n = 1 – “x”; 则 n + ” objects” 输出为( )
    A. “1-x object”
    B. 1 Object
    C. NaN
    D. “NaN objects”
    D
  • 50.代码var n = 123456.789; 代码n.toFixed(0)的输出是( )
    A. 123456
    B. 123457
    C. 123456.00
    D. 123456.789
    B
  • 51.代码var n = 123456.789; 代码n.toPrecision(4)的输出是( )
    A. 1.2e+5
    B. 1.235e+5
    C. 123456.8
    D. 123456.7890
    B
  • 52.parseFloat(“3.14 meters”)的输出结果是( )
    A. 3
    B. “3.14 meters”
    C. 3.14
    D. 3.
    C
  • 53.parseInt(“.1”)的输出结果是( )
    A. 0
    B. 1
    C. NaN
    D. 0.1
    C
  • 54.parseFloat(“$72.47”)的输出结果是( )
    A. $72.47
    B. 72.47
    C. $72
    D. NaN
    D
  • 55.JavaScript中表达式parseInt(“X8X8”) +parseFloat(“8”)的结果是()
    A. 8+8
    B. 88
    C. 16
    D. NaN
    D
  • 56.parseInt(“077”,8)的输出结果是( )
    A. 77
    B. 077
    C. 63
    D. NaN
    C
  • 57.({x:1, y:2}).toString()的输出结果是( )
    A. {x:1, y:2}
    B. “[object Object]”
    C. NaN
    D. “”
    B
  • 58.下面哪一个语句定义了一个名为pageNumber的变量并将它的值赋为240?
    A. var PageNumber=240
    B. pagenumber=240
    C. var pageNumber=240
    D. var int named pageNumber=240
    C
  • 59.在JavaScript,以下哪个变量名是非法的()?
    A. Name
    B. 9Name
    C. Name_a
    D. Name9
    B
  • 60.在JavaScript中,()变量在函数外声明,并可从脚本的任意位置访问。
    A. 局部
    B. 全局
    C. typeof
    D. New
    B

二、综合题

  • 1.下面的代码输出的值是什么?为什么?
    var scope = “global”;
    function checkscope() {
    var scope = “local”;
    return scope;
    }
    checkscope();
  • 2.下面的代码输出的值是什么?为什么?
    scope = “global”;
    function checkscope2() {
    scope = “local”
    myscope = “local”;
    return [scope, myscope]
    }
    checkscope2();
    scope;
    myscope;
  • 3.下面的代码输出的值是什么?为什么?
    var scope = “global scope”;
    function checkscope() {
    var scope = “local scope”;
    function nested() {
    var scope = “nested scope”;
    return scope;
    }
    nested();
    }
    checkscope();
  • 4.下面的代码输出的值是什么?为什么?
    var scope = “global”;
    function f() {
    console.log(scope);
    var scope = “local”;
    console.log(scope);
    }
    f();
  • 5.下面的代码输出的值是什么?为什么?
    function isWinner(player, others) {
    var highest = 0;
    for (var i = 0, n = others.length; i< n; i++) {
    var player = others[i];
    if (player.score> highest) {
    highest = player.score;
    }
    }
    return player.score> highest;
    }

三、编程题

  • 1.编写比较两个数组的函数
  • 2.实现判断NaN的函数 isNaN()
  • 3.JavaScript中如何检测一个变量是—个string类型?请写出函数实现。
  • 4.计算下面的变量值:
    var a = (Math.PI++);
    var b = (Math.P++);
    alert(a);
    alert(b);
  • 5.请给出下面a、b、c的输出结果:
    var a=parseInt(“11”, 2);
    var b=parseInt(“02”, 10);
    var c=parseInt(“0 9/08/2009”);
  • 6.编写JavaScript脚本,生成0-7之间的随机整数
  • 7.使用JavaScript求两个数的最大公约数
分享&收藏

转载请注明:陈童的博客 » JavaScript中的类型、值和变量练习题

喜欢 (11)
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
'; } if( dopt('d_footcode_b') ) echo dopt('d_footcode'); ?>