js中的隱式類型轉化

來源:互聯網
上載者:User

標籤:line   ber   style   white   tostring   bsp   mono   if判斷   number   

//1.數學運算的時候

 var num = +‘123‘;

var num1 = -‘123‘;

var num2 = ‘123‘/1;

console.log(typeof num1)

console.log(typeof num)

//2.new 運算子


var num = new Number(‘你好‘); 

console.log(num)

//3 字串拼接 無論是任何其他資料類型的值跟字串進行拼接,都會變成字串


var ret = ‘123‘+456;//123456

var ret2 = ‘123‘+{}// 對象?‘123[object Object]‘

var ret3 = ‘123‘+[3,4,5]//‘1233,4,5‘

//數群組轉換成字串是特別的一種形式,是會轉換成‘3,4,5‘

console.log(ret)

console.log(ret2)

console.log(ret3)

//會先把數組456 轉換為字串,然後跟前面的字串‘123‘進行字串拼接的操作

console.log(typeof (new Number).toString())// string 資料類型

 //4 if 判斷語句

if(‘chuanzhi‘){//if判斷語句內部會把其他資料類型的值轉換為布林值資料型別,然後進行判斷

  console.log(‘chuanzhi‘)

}

 

 

 

 


  

 

js中的隱式類型轉化

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.