JavaScript - typeof(), prompt(), String(), Number()
JavaScripttypeof() : to check the data type like number, string, bool
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>title</title>
<script type="text/javascript">
var str = "This is String";
var num = 500;
var bool = true;
alert(typeof(str));
alert(typeof(num));
alert(typeof(bool));
</script>
</head>
<body>
</body>
</html>
prompt(String message, String default) : a function to get a value for a variable
Number() : coverting data type as number. if its not a number, converting to "Nan"
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>title</title>
<script type="text/javascript">
var input = prompt("number input", "number");
var numberInput = Number(input);
alert(typeof(numberInput)+": "+numberInput);
</script>
</head>
<body>
</body>
</html>
String() : same as Number() function
'JavaScript' 카테고리의 다른 글
JavaScript - bool data type converting (0) | 2019.09.14 |
---|---|
JavaScript - Function Executing Process (0) | 2019.09.14 |
JavaScript - Global Variable (0) | 2019.09.14 |
JavaScript - Hoisting (0) | 2019.09.14 |
JavaScript - window.onload (0) | 2019.09.14 |