1.JS中的数据类型有哪些?
_____________________________________________
2.JS中强制类型转换为number类型的方法有哪些?
_____________________________________________
3.字符串转换成数组的方法是_________,数组转换成字符串的方法是________
4.手写js‘数组去重’?
5.分别输出为________ ,_________ ,________ ,_________
function test() {
var n = 4399;
function add() {
n++;
console.log(n);
}
return {n: n, add: add};
}
var result = test();
var result2 = test();
result.add();
result.add();
console.log(result.n);
result2.add();
6.console.log(a[b])输出为________.
var a={} , b={key:'b'} , c={key:'c'};
a[b]=123;
a[c]=456;
console.log(a[b]);
7.分别输出为________ ________?
var a = 1;
function fn1(a){
alert(a);
a = 2;
}
fn1();
alert(a);
8.分别输出为________ ________?
var m = 1;
function add(n){
return n = n+ 1;
}
y = add(m);
function add(n){
return n = n +3;
}
z = add(m);
console.log(y);
console.log(z);
9.当前this指向__________?
var big = "万达老师";
var obj = {
big:"宋伟老师",
showBig:function(){
return this.big;
} }
obj.showBig.call(big);
10.分别输出为________ ________ ________ _______?
function F() {}
Object.prototype.b = 2;
F.prototype.a = 1;
var f = new F();
console.log(f.a)
console.log(f.b)
console.log(F.a)
console.log(F.b)
答案
1.基础数据类型:Undefined、Null、Boolean、String、Number、Symbol
引用数据类型:Object、Array、Date、RegExp、Function
2.Number() parseInt() parseFloat()
var a = "123"; a = a - 0; console.log(typeof a); console.log(a);
3.数组转字符串
var a, b;
a = new Array(0,1,2,3,4);
b = a.join("-");
字符串转数组
var s = "abc,abcd,aaa";
ss = s.split(",");// 在每个逗号(,)处进行分解。
4.
function unique10(arr) {
//Set数据结构,它类似于数组,其成员的值都是唯一的
return Array.from(new Set(arr)); // 利用Array.from将Set结构转换成数组
}
console.log(unique10([1, 1, 2, 3, 5, 3, 1, 5, 6, 7, 4]));
5.4400 4401 4399 4400
6.456
7.undefined 1
8.4 4
9.String.prototype
10.1 2 undefined 2
标签:________,function,面试题,console,log,前端,技术,add,var From: https://www.cnblogs.com/qinlinkun/p/18061373