소스 코드를 기록하는 남자

JavaScript - typeof(), prompt(), String(), Number()

JavaScript

typeof() : 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>

alert(typeof(str));

 

alert(typeof(num));
alert(typeof(bool));

prompt(String message, String default) : a function to get a value for a variable

var input = prompt("Message", "Hello")

 

 alert(input) : Input is "Hello" 

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