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

112
Views
Does javascript switchs runs continuously

i was wondering if switches runs continuously or does not need of setIntervals to run (forever). i'm making a game where in a level value changes and the switch will change all entities position based on the level;

let LEVEL = 0;

switch (LEVEL) {
    case 1: 
    player.x = 64;
    player.y = 64;
    enemy.x = 32;
    enemy.y = 32;
    break;
    case 2: 
    player.x = 0;
    player.y = 64;
    enemy.x = 72;
    enemy.y = 56;
    break;
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

No. A switch is like every other statement in JavaScript: It only runs when it's reached in the step-by-step execution of the code. Your example would run exactly once, for instance. To run more often would require that you put it in a loop (but then nothing else can run except that loop) or, as you said, call a function that contains the switch from a timer.

i'm making a game where in a level value changes and the switch will change all entities position based on the level

Put the switch in a function that you call when you change the level.

over 4 years ago · Santiago Trujillo 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!