1、何检测一个变量类型
html
typeof(obj) === "string"
obj.constructor === String //true,是字符串
转载 ?/blog.csdn.net/bifuguo/article/details/81415699
2、获取URL参数
var href=window.location.href
var arr=href.split('?')
var obj={}
var arr1=arr[1].split('=')
for(var i=0;i<arr1.length;i++){
obj[arr1[0]]=arr1[1]
}
alert(obj['id'])
3、获取冒号后面文字
**1**
var reg=/[^:]*:([^:]*)/
var str=this.inputvalue.replace(reg,"$1")
**2**
var st=this.inputvalue.split(":")
var str=st[1]
```)
**html**
```javascript
typeof(obj) === "string"
obj.constructor === String //true,是字符串
4、编程题
1)add(2,3)和add(2)(3)编写一个函数,都返回5
**1 这种方案只适合两个参数,不适合多个参数**
function sum(x,y){
var sum=x
if(y){
return sum+y
}else{
return function(z){
return sum+z
}
}
console.log(sum(2,3))
console.log(sum(2)(3))
**2 适合多个参数。**
function add(x) {
var sum = x;
var tmp = function (y) {
sum = sum + y;
return tmp;
};
tmp.toString = function () {
return sum;
};
return tmp;
}
console.log(add(1)(2)(3)); //6
console.log(add(1)(2)(3)(4)); //10
console.log(sum(2,3))
5、实现预加载一张图片,加载完成后显示在网页中并设定其高度为50px,宽度为50px
先new Image()获取一个图片对象,然后在图片对象的onload中设置宽度和高度。
参考: https://www.cnblogs.com/haoyijing/p/5818236.html
<img src="" id="img"/>
var img= document.getElementById('img');
addImg('http://systemdev.hzpgc.com/upload/brand/201904/5cc50088e1ed68.87546128.jpg');
function addImg(url){
var img1=new Image()
img1.src=url
img1.onload=function(url){
img.src=this.src
img.height=50
img.width=50
}
}
6、面试题
25个最基本的JavaScript面试题:
https://blog.csdn.net/qq_20389175/article/details/51119478
前端程序员经常忽视的一个JavaScript面试题
1: https://github.com/Wscats/Good-text-Share/issues/85
2、 https://blog.csdn.net/liuxinyang666/article/details/78849079
彻底理解js中this的指向
https://www.cnblogs.com/pssp/p/5216085.html
https://www.cnblogs.com/pssp/p/5215621.html