js的输出方法,数字类型和字符串类型相互转换

js中的输出

        let a = 2;
        let b = '2';
        // 在浏览器console中输出 typeof检测当前变量的数据类型
        console.log(a, typeof a, b, typeof b);
        //在浏览器中弹窗输出
        alert(a);
        //confirm弹出选择窗并返回选择的数值
        let is_delete = confirm('你确定删除吗?');
        alert(is_delete);
        if (is_delete){
            //在网页输出内容
            document.write('删除成功!')
        }else {
            document.write('删除失败!')
        }
    // ``反引号${}格式化输出 es6语法
    let s2 = `姓名:${name}年龄:${age}岁`;
    console.log(s2);

 

 

js中的数字类型和字符串类型相互转换

        let name = 'rock';
        let age = 23;
     console.log(String(age))  console.log(age.toString(),
typeof age.toString()); //隐式转换把Number类型转换陈String类型 let age1 = '' + age; console.log(typeof age1, age1); let new_str = name + age; console.log(new_str, typeof new_str);       //字符串转数值parseInt console.log(name, typeof name, typeof parseInt(name)); // 取整 console.log(parseInt(4.9))

 

posted @ 2019-02-24 12:28  平平无奇小辣鸡  阅读(1154)  评论(0)    收藏  举报