3.2typeof 类型转换
程序员文章站
2022-06-22 16:49:04
内容上下会有些衔接。。。swich循环语句var n = 3;switch(n){case 1:console.log('a');case 2:console.log('b');case 3:console.log('c');}这是一道题var n = 'a';switch(n) {case "a":console.log('a');break;case 2:console.log('b');break;c...
内容上下会有些衔接。。。
swich循环语句
var n = 3;
switch(n){
case 1:
console.log('a');
case 2:
console.log('b');
case 3:
console.log('c');
}
这是一道题
var n = 'a';
switch(n) {
case "a":
console.log('a');break;
case 2:
console.log('b');break;
case true:
console.log('c');break;
}
这是一道题
var date = window.prompt('inout');
switch(date) {
case "monday":
case "tuesday":
case "wednesday":
case "thursday":
case "friday":
console.log('working');break;
case "saturday":
case "sunday":
console.log('relax');break;
}
这是一道题
var i = 0;
while(1){
i ++;
console.log(i);
if(i > 100){
break;
}
}
这是一道题
var i = 0;
var sum = 0;
for (i = 0; i < 100; i++) {
sum += i;
console.log(i);
if (sum > 100) {
break;
}
}
这是一道题
for (var i = 0; i < 100; i++) {
if (i % 7 == 0 || i % 10 == 7) {
continue;
}
console.log(i);
}
// continue直接开始下一次循环
这是一道题
var arr = [1,2,3,4,6,'da',"gasf",undefined];
for (var i = 0; i < arr.length; i++) {
console.log(arr[i]);
}
这是一道题
var deng = {
lastname : "Deng",
age : 40,
sex : undefined,
wife : "xiaoliu",
father : "dengdaye",
son : "xiaodeng",
handsome : false,
}
console.log(deng.lastname);
deng.lastname = "Old Deng";
console.log(deng.lastname);
1.面向过程
2.面向对象
typeof可以返回number string boolean object undefined function
var num = function(){};
console.log(typeof(num));
var num = 123;
console.log(typeof(num));
var num = 1 * "1";
console.log(typeof(num) + " : " + num);
类型转换
var demo = "123";
var num = Number(demo);
console.log(typeof(num) + " : " + num);
var demo = "123abc";
var num = parseInt(demo);
console.log(typeof(num) + " : " + num);
var demo = "10";
var num = parseInt(demo, 16); //以16为基底转化成10进制
console.log(typeof(num) + " : " + num);
var demo = "123.33fefsd";
var num = parseFloat(demo);
console.log(typeof(num) + " : " + num);
var demo = "123.3212adsdwa";
var num = String(demo);
console.log(typeof(num) + " : " + num);
var demo = "123";
var num = Boolean(demo);
console.log(typeof(num) + " : " + num);
var demo = "20";
var num = demo.toString(8); //把demo的值转化成8进制的数的结果
console.log(typeof(num) + " : " + num);
把二进制10000转化成16进制的数
var num = 10000;
var text = parseInt(num,2);
console.log(text.toString(16));
隐式类型转换
console.log(isNaN(null));
var a = "abc";
a ++;
console.log(a + " : " + typeof(a));
var a = "a" + 1;
console.log(a + " : " + typeof(a));
var a = 1 == true;
console.log(a + " : " + typeof(a));
var a = 1 === "1";
console.log(a + " : " + typeof(a));
console.log(typeof(typeof(a)));
console.log(typeof(a + ""));
这是一群题
alert(typeof(a));
alert(typeof(undefined));
alert(typeof(NaN));
alert(typeof(null));
var a ="123abc";
alert(typeof(+a));
alert(typeof(!!a));
alert((typeof(a +""));
alert(1=="1");
alert(NaN == NaN);
alert(NaN == undefined);
alert("11" + 11);
alert(1==="1");
alert(parselnt("123abc")) ;
var num = 123123.345789;
alert(num.toFixed(3));
本文地址:https://blog.csdn.net/qq_49295769/article/details/107302330
上一篇: 菜鸟的复习之路——HTML进阶篇(下)
下一篇: socket编程总结