function hi(){
var a;
alert(a);
}
hi();//undefined
var a=1;
function hi(){
alert(a);
var a='higuys';
alert(a);
}
hi();//undefined higuys
var str='abcdefg';
console.log(str.substr(4,3));//deg
console.log(str.substring(4,7));//deg
console.log(0.1+0.2==0.3);//false
(function (){
console.log(1);
setInterval(function(){
console.log(2);
},1000);
setTimeout(function(){
console.log(3);
},0);
console.log(4);
})();//1 4 3 2(一秒一个)
a();//报错
b();
var a=function(){
console.log("a");
}
var b=function(){
console.log("b");
}
(function(){
var a=b=3;
})();
// console.log(a);//报错
console.log(b);//3
console.log("a undefined?"+(typeof a!=='undefined'));//a undefined?false
console.log("b undefined?"+(typeof b!=='undefined'));//b undefined?true
var str2='abdezxt';
var arr2=[];
for (var i = str2.length - 1; i >= 0; i--) {
arr2.push(str2[i]);
}
console.log(arr2);//txzedba
编写一个页面,打开后从10开始倒数,并在倒计时完成时跳转到网页访问记录的上一页
<h1 id="con">10</h1>
<script>
var x=10;
var timer=setInterval(function(){
x--;
if (x<=0) {
clearInterval(timer);
window.history.back();
}
con.innerHTML=x;
},1000);
</script>
2.iframe和frameset的区别?
frameset是把整个页面分为多个部分,就像把表格分为多个行和列一样
而iframe是在整个页面中嵌入一个页面,就像在网页中插入图片一样,位置和大小可以随意设置
(1) var str= 'abc123';
var num= parseInt(str);
console.log(num);//NaN
if(num==NaN){
alert(NaN);
}else if(num==123){
alert(123);
}else if(typeof num== 'number'){
alert('number');
}else{
alert('str');
}//number
(2) var a='abc'+123+456
console.log(a);//abc123456
(3)var a='456'-'123'
console.log(a);//333
(4) var a=1;
var b='2';
var c=a>b?(a<b?a:b):(a==b?a:b);
console.log(c);//2
(5) var a=5&3;
console.log(a);//1
(6) for(var i=0;i<10;i++){
alert(i);
break;
}
alert(i);//0 0
(7) for(var i=0;i<10;i++){
continue;
alert(i);
}
alert(i);//10
(8) var a=0;
function fun(){
alert(a);
var a=10;
}
fun();
alert(a);//undefined 0
(9) var a=0;
var b=a;
b++;
alert(a);//0
(10)
var o={};
o.a=0;
var b=o;
b.a=10;
alert(o.a);//10
(11) var n=0;
function a(){
var n=10;
function b(){
n++;
alert(n)
}
b();//11
return b;
}
var c=a();
c();//12
alert(n);//0
function fun(a,b,c){ var l=arguments.length; var num=0; for(var i=0;i<l;i++){ num+=arguments[i]; } alert(num) } fun(1,2,3);//6 fun(1,2,3,4);//10
function fun(){
this.a=0;
this.b=function(){
alert(this.a);
}
}
fun.prototype={
b:function(){
this.a=20;
alert(this.a);
},
c:function(){
this.a=30;
alert(this.a)
}
}
var my_fun=new fun();
my_fun.b();//0
my_fun.c();//30