-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Canvas
JS Graphics & Charts
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Canvas
JS Graphics & Charts
In JavaScript, a Boolean represents one of two values:
true
false
These values are used to control program logic in:
if
/else
conditions
Loops
Comparisons
Logical operations (&&
, ||
, !
)
let isOnline = true;
let isLoggedIn = false;
They can be assigned directly or returned from expressions:
let x = 10 > 5; // true
function isAdult(age) {
return age >= 18;
}
console.log(isAdult(20)); // true
Functions often return Boolean values to indicate conditions.
You can convert any value to Boolean using the Boolean()
function:
Boolean(0); // false
Boolean(1); // true
Boolean(""); // false
Boolean("hello"); // true
Boolean(null); // false
Non-empty strings: "hello"
Non-zero numbers: -1
, 3.14
Objects and arrays: []
, {}
false
0
""
(empty string)
null
undefined
NaN
if ("hello") {
console.log("This is truthy");
}
if (0) {
console.log("This won't run");
}
Booleans are mostly used inside if
, while
, and other conditions:
let loggedIn = false;
if (!loggedIn) {
console.log("Please log in.");
}
Q1. How do you declare a Boolean variable in JavaScript?
Q2. What value does the expression 10 > 5
return in JavaScript?
Q3. Which function is used to convert any value into a Boolean?
Q4. What will Boolean("0")
return? Why?
Q5. How do you check if a user is not logged in using a Boolean variable?
Q6. Which values are considered falsy in JavaScript?
Q7. What will be the Boolean value of an empty array ([]
)?
Q8. How do you return a Boolean from a function checking if a number is even?
Q9. What happens when you use a Boolean inside an if
statement?
Q10. How can you convert a number to Boolean using double negation (!!
)?
Q1: Which of the following is a Boolean value in JavaScript?
Q2: What will Boolean(0) return?
Q3: What is the output of: Boolean("hello")?
Q4: Which of these is considered falsy?
Q5: What is the Boolean result of Boolean(null)?
Q6: What does the ! (not) operator do in JavaScript?
Q7: What is the output of !!"JavaScript"?
Q8: Which of the following values is truthy?
Q9: Which operator is used to check if a Boolean variable is false?