Use if statement and Boolean conversion at the same time in JavaScript
Description
The following code shows how to use if statement and Boolean conversion at the same time.
Example
<!-- ww w . j a va 2s .com-->
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var aString = "Hello world!";
if (aString){
document.writeln("value is true"); //output
}
aString = "";
if (aString){
document.writeln("value is true");
}else{
document.writeln("value is false"); //output
}
aString = null;
if (aString){
document.writeln("value is true");
}else{
document.writeln("value is false"); //output
}
</script>
</head>
<body>
</body>
</html>
The code above generates the following result.
Javascript Tutorial Boolean
Add function to buildin type in JavaScript
Check the difference between Boolean Object...
Convert Boolean to string in JavaScript
Convert a empty string to Boolean type in J...
Convert a nonempty string to Boolean type i...
Convert boolean to string by calling its to...
Convert undefined to boolean value with Boo...
Converts a non-zero value to Boolean type i...
Converts a zero value to Boolean type in Ja...
Create Boolean Object from boolean literal ...
Create boolean from null in JavaScript
Create boolean from object in JavaScript
Create two boolean type variables in JavaSc...
Get the Boolean value contained in the Bool...
Use and operator to calculate boolean value...
Use boolean literal true and false to creat...
Use false to create boolean variable in Jav...
Add function to buildin type in JavaScript
Check the difference between Boolean Object...
Convert Boolean to string in JavaScript
Convert a empty string to Boolean type in J...
Convert a nonempty string to Boolean type i...
Convert boolean to string by calling its to...
Convert undefined to boolean value with Boo...
Converts a non-zero value to Boolean type i...
Converts a zero value to Boolean type in Ja...
Create Boolean Object from boolean literal ...
Create boolean from null in JavaScript
Create boolean from object in JavaScript
Create two boolean type variables in JavaSc...
Get the Boolean value contained in the Bool...
Use and operator to calculate boolean value...
Use boolean literal true and false to creat...
Use false to create boolean variable in Jav...