- If it is a real value it will return true and without a real value it will return false.
- So all of the value will return true or false value in the condition statement.
Code:-
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <script>
- /*
- JavaScript Falsy Values: null, false, 0, undefined, NaN, and "".
- */
- function chk_null(val)
- {
- if (val)
- alert("It is true");
- else
- alert("It is false");
- }
- function chk_false(val)
- {
- if (val)
- alert("It is true");
- else
- alert("It is false");
- }
- function chk_zero(val)
- {
- if (val)
- alert("It is true");
- else
- alert("It is false");
- }
- function chk_undfnd(val)
- {
- if (val)
- alert("It is true");
- else
- alert("It is false");
- }
- function chk_NaN(val)
- {
- if (val)
- alert("It is true");
- else
- alert("It is false");
- }
- function chk_emptystr(val)
- {
- if (val)
- alert("It is true");
- else
- alert("It is false");
- }
- </script>
- </head>
- <body>
- <h2>False Values</h2>
- <button onclick="chk_emptystr('');">Check empty string</button>
- <button onclick="chk_emptystr(' ');">Check string</button>
- <button onclick="chk_null(null);">Check Null</button>
- <button onclick="chk_false(false);">Check false</button>
- <button onclick="chk_zero(0);">Check zero</button>
- <button onclick="chk_undfnd(undefined);">Check undefined</button>
- <button onclick="chk_NaN(NaN);">check NaN</button>
- </body>
- </html>
- </html
True and false values :- JavaScript
Reviewed by Network security
on
November 05, 2019
Rating:
No comments: