JavaScript If Statement Example

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <title>JavaScript IF Condition</title>
</head>
<body>
<pre>
<script type="text/javascript">

    var a = 5;
    if (a) {    // variable a = 5 value, so expression of 'a' return true
        document.write("Value of a: " + a);
    }

</script>
</pre>
</body>
</html>

Run it...   »

Example Result