Javascript Data Type How to - Change undefined variable to empty string








Question

We would like to know how to change undefined variable to empty string.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
<!--from   w ww.j  a va2 s .  co  m-->
var i;
if (i==undefined){
    i="";
}
document.writeln(typeof i);

</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: