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

176
Views
Early return from a script (without a function)

I have multiple duplicated external scripts that I want to run just once.

I would like to return early on those scripts after the first time doing a small modification to those scripts, something like:

if (window.this_script_have_been_loaded) {
  something_like_return
}

// rest of script

window.this_script_have_been_loaded = true

But I do not want to add a big if or function around the existing code to make it easier to manage. Is there a return statement for scripts?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

To prevent code from running, place this code inside a block statement and exit this block if needed with a break statement and a label.

label: {
    console.log('before');
    if (true) break label;
    console.log('after');
}

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!