What is JavaScript Short Circuit?
Asad Anik
Posted on October 4, 2022
Let’s talk about JavaScript / React Falsely value ignorance. It’s call JavaScript Short Circuit Evaluation. In React we can learn and we also know about how to developing Applications. But We don’t know about some special things like JavaScript Short Circuit.
In JavaScript short-circuiting, an expression is evaluated from left to right until it is confirmed that the result of the remaining conditions is not going to affect the already evaluated result.
And there is 2 types of short circuits.
- And Short Circuit
- Or Short Circuit
And Short Circuit
When we are saying if something is there so do like this specific work or if you here then i will go. 🙄 I know that seems confusing here. So let’s see the real world example.
const iAmAStudent = true;
iAmAStudent && console.log('Yes you are a student!');
So here we saw the and short circuit example, there is a log with iAmAStudent value when true. 😎
Or Short Circuit
When the decision is for just looking up choice who is 💝 present right now, then this will execute. This is actually the conditioning stages value.
const HOST = process.env.HOST || 'localhost';
console.log(HOST);
Here we can see the useful example of or short circuit. If you have the value of process.env.HOST so okay it’s fine 🙃 but if you don’t has the .env value so it will set the ‘localhost’ for you.
Posted on October 4, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.