Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH RUST

Basic JavaScript

JS Tutorial JS Syntax JS Variables JS Operators JS If Conditions JS Loops JS Strings JS Numbers JS Functions JS Objects JS Dates JS Arrays JS Sets JS Maps JS Math JS RegExp JS Data Types JS Errors JS Debugging JS Events JS Programming JS References JS UTF-8 Characters JS Versions

JS Advanced

JS Functions JS Objects JS Classes JS Iterations JS Promises JS Modules JS HTML DOM JS Windows JS Web API JS AJAX JS JSON JS jQuery JS Graphics JS Examples JS Reference


JavaScript Logical Operators

Logical Operators

Logical operators are used to combine boolean expressions.

Logical operators can be used to modify the results of comparisons.

Typically, you will use a comparison operator to check a condition, and a logical operator to combine conditions into more complex logic.

JavaScript Logical Operators

Logical operators are used to determine the logic between variables or values.

Given that x = 6 and y = 3, the table below explains the logical operators:

Oper Name Example Try it
&& AND (x < 10 && y > 1) is true Try it »
|| OR (x === 5 || y === 5) is false Try it »
! NOT !(x === y) is true Try it »

JavaScript Logical AND

The && operator returns true if both expressions are true, otherwise false:

Example

let x = 6;
let y = 3;
let z = (x < 10 && y > 1)
Try it Yourself »

JavaScript Logical OR

The || operator returns true if one or both expressions are true, otherwise false:

Example

let x = 6;
let y = -3;
let z = (x > 0 || y > 0)
Try it Yourself »

JavaScript Logical NOT

The NOT operator (!) returns true for false expressions and false for true expressions.

Example

let x = (5 == 8);
let y = !(5 == 8)
Try it Yourself »

The Nullish Coalescing Operator (??)

The ?? operator returns the first argument if it is not nullish (null or undefined).

Otherwise it returns the second argument.

Example

let name = null;
let text = "missing";
let result = name ?? text;
Try it Yourself »

Browser Support

?? is an ES2020 feature.

ES2020 is fully supported in all modern browsers since September 2020:

Chrome
85
Edge
85
Firefox
79
Safari
14
Opera
71
Aug 2020 Aug 2020 Mar 2020 Sep 2020 Sep 2020


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.