学过数据类型之后就可以做这个作业了
课后作业
一、问答题
1.JS中常用的数据类型有哪些?
数据类型分为基础类型数据和引用类型数据。
其中基础类型数据(7个)有:number、string、boolean、null、undefine、bigint(大数据值)、symbol(唯一值)。
引用类型有:对象(new Arry、new RegExp、new date )、函数
2.浏览器中常用的内核有哪些?
webkit 、gecko火狐 、blink、trident内核…
3.数据类型之间的区别?
主要区别两个:基本数据类型是按照值操作,值存储在栈内存,引用数据类型是按照堆内存地址来操作的,我们需要把对象的键值对存储在堆内存中,我们操作的是堆内存的应用地址;各种类型之间自己的特有属性特征就是他们的第二个区别。
4.列举常用的关键字(在JS中有特殊含义的)和保留字(未来可能会成为关键字的)
var let new function
break
case
catch
continue
default
delete
do
else
finally
for
function
if
in
instanceof
new
return
switch
this
throw
try
typeof
var
void
while
…
5.JS中创建变量的几种常用方式?
- var
- let
- const
- function 创建函数
- class 创建一个类
- import / require 基于ES6Module或者Common.js规范导入模块
二、练习题
1.写出下面结果输出的答案 (阿里面试题)
let a = {
n: 1
};
let b = a;
a.x = a = {
n: 2
};
console.log(a.x);
console.log(b);
=>undefine
=>{n:1 , x:{n:2} }
2.分别写出下列表达式输出的结果 (腾讯面试题)
var a = 'abc' + 123 + 456;
var b = '456' - '123';
var c = 100 + `true` + 21.2 + null + undefined + "Tencent" + [] + null + 9 + false;
console.log(a,b,c);
结果为:(‘abc123456’ , 333 ,NaNTencentnull9false)
3.写出下列代码的输出结果 (腾讯面试题)
var str = 'abc123';
var num = parseInt(str);
if (num == NaN) {
alert(NaN);
} else if (num == 123) {
alert(123);
} else if (typeof num == 'number') {
alert('number');
} else {
alert('str');
}
结果为 ‘number’
4.写出下列代码的输出结果 (腾讯面试题)
var a = 0;
var b = a;
b++;
alert(a)
var o = {};
o.a = 0;
var b = o;
b.a = 10;
alert(o.a)
结果为:“0”,“10”
5.能输出”1”(字符串1)的有哪些?
A.alert(1) //输出的是"1",因为基于alert/confirm等输出结果,都会把内容转换为字符串再输出
B.console.log(parseInt(1.3))//parseInt('1.3') =>1
C.console.log(1) //console.log输出的内容还是原本的数据格式
D.console.log(isNaN(1))
E.console.log(parseInt("1"))//parseint输出的是数字
结果为:a
6下面结果是”undefined”的是
A.console.log(alert(1)) //先执行alert(输出"1"),把alert执行的的结果在输出=>undefine
B.typeof undefined //不管返回的结果是啥,首先都是一个字符串=>"undefined"
C.console.log(parseInt(undefined)) //=>"undefined" typeof返回的结果首先是一个字符串 =>NaN
D.isNaN(undefined)//=>isNaN检测值,如果值不是数字类型,先基于Number把其转换为数字类型,然后再检测 =>Number(undefined) =>NaN =>isNaN(NaN) =>true
结果为b
7.下面结果能得到true的是
A.isNaN(null)
B.isNaN(parseInt(null)) //=>parseInt("null") =>NaN =>isNaN(NaN) =>true
C.Number(null)
D.parseFloat(null)//=>parseFloat("null") =>NaN
结果为b
8.输出下面程序的结果
parseInt("")//Number和parseInt在转换为数字的时候,规则是不一样的
Number("")
isNaN("")//=>需要先调用Number转换为数字再检测 isNaN(0) =>false
parseInt(null)
Number(null)
isNaN(nul)//=>isNaN(Number(null)) => isNaN(0) =>false
parseInt("12px")
Number("12px")
isNaN("12px")
结果为:NaN 0 false NaN 报错 true NaN true
9.下面程序输出的结果
if (isNaN(NaN) == "") {
console.log("珠峰")
} else {
console.log("培训")
}
结果:培训
10.下面程序输出的结果
let x = [1, 2, 3];
let y = x;
let z = [4, 5, 6];
y[0] = 10;
y = z;
z[1] = 20;
x[2] = z = 30;
console.log(x, y, z);
结果为:[ 10, 2, 30 ] ,[ 4, 20, 6 ],30
三、扩展题
1.浏览器常用的输出方式,除了console.log还有哪些?
答:console.table() 、 console.dir()、console.time()、cosole.timeEnd() 、alert()、prompt()、confirm()…
2.< script > 标签放到页面头部和尾部的区别,以及解决办法?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>珠峰练习题</title>
<!-- IMPORT JS -->
<script>
// JS代码
</script>
</head>
<body>
......
<!-- IMPORT JS -->
<script>
// JS代码
</script>
</body>
</html>
因为代码是自上而下执行的,放在头部会先先去解析加载JS代码,此时HTML代码还未加载,会增加页面渲染的时间;放在脚部会先渲染页面。放在头部可以加defer、async