Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
Why isn't this if statement running?

I'm learning Javascript and I've gotten to conditionals. When I declare a variable 'sale' and assign it a value of true, my if statement runs, but if I reassign the value of sale to false, the code does not execute. Why is this happening?

let sale = true;

if (sale){
  console.log('Time to buy!');
}

The above code executes, but the following code doesn't and I don't understand why. I'm new to coding.

let sale = false;

if (sale = false){
  console.log('Enough inventory');
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The "=" statement in most programming languages is an assignment operator, it assigns values to certain variable names. What you are looking for is a "==" this checks if something is equal or not.

let sale = false;

if (sale == false){
  console.log('Enough inventory');
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!