<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
//强制类型转换自动类型转换?
//强制类型转换 : 把一个类型转成另外一个类型
//Number() String() Boolean()
//var a = 123;
//console.log( String(a) ); // '123'
//var a = 'hello';
//console.log( String(a) ); // 'hello' 你把一个相同的类型进行强制转换,是不会有任何作用。
//var a = true;
//console.log( String(a) ); // 'true'
//var a = null;
//console.log( String(a) ); // 'null'
//------------------------------
//var a = 'hello';
//console.log( Number(a) ); // NaN
//console.log( typeof NaN ); // 'number'
//var a = true;
//console.log( Number(a) ); // true -> 1 false -> 0
//var a = null;
//console.log( Number(a) ); //0
//-------------------------------
//var a = 123;
//console.log( Boolean(a) ); // 非0数字都会转成true , 0转成false
//var a = ' ';
//console.log( Boolean(a) ); // 非空字符串会转成true,空字符转成false
//var a = null;
//console.log( Boolean(a) ); // false
//--------------------------------------------------
//自动类型转换?不是通过JS语法转换的,而是计算机程序自动进行转换的
//console.log( 1 + '2' ); -> String(1) + '2' -> '12'
//console.log( 1 - '2' ); // 减号只有减法的作用,那么 1 - Number('2') -> -1
/* if(1){ //-> Boolean(1) -> true
} */
//练习:
var t = 'text';
var c = '猜';
var str = '<div><input type="'+t+'"><button>'+c+'</button></div>';
console.log(str);
</script>
</body>
</html>