Created
May 15, 2020 10:52
-
-
Save FurkanKozen/b478aaad57a82d69963e763defb933b2 to your computer and use it in GitHub Desktop.
Some type conversion methods in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var numberContent = ~~"1"; | |
var stringContent = ~~"string sample"; | |
var stringContent2 = +"string sample 2"; | |
var booleanContent = !!"false"; | |
console.log(typeof numberContent); //"number" | |
console.log(numberContent); //1 | |
console.log(typeof stringContent); //"number" | |
console.log(stringContent); //0, but should be NaN! | |
console.log(typeof stringContent2); //"number" | |
console.log(stringContent2); //NaN, this is what it should be. | |
console.log(typeof booleanContent); //"boolean" | |
console.log(booleanContent); //true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment