Short Circuiting AND (&&)

Understanding how the AND operator works in JavaScript

The AND operator (&&) evaluates operands from left to right and returns the first falsy value it encounters. If all values are truthy, it returns the last value.

In this mini project, we will demonstrate how short-circuiting works with the AND operator.

Check the code in index.js to see examples of short-circuiting with the AND operator.

Here are some examples:

			
const user = {
    userName: 'Tom',
    role: 'admin',
}

user.role === 'admin' && console.log('Hi Admin!')
			
		

References:

Open the console to see the output of the code.


View Challenge