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

166
Views
can I update a variable by making its value an function which gets an external value every 10 milliseconds with setInterval?

Can I update a variable by making its value a function that gets an external value every 10 milliseconds with setInterval? I'm a beginner so be kind.

var scrollTop = setInterval(function() {
var scrollTop = (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;
}, 10);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

These are some of the observations and suggestions to improve your code,hope this will help you.

  • Set Interval will return an interval ID which means your var scrollTop will have an id value like(0,1,2,4) instead of an offset value.

  • set Interval will take a callback function means just define your function outside of the interval and use that. it will make your code cleaner and easy to debug.

also you are beginner so you can read about this terms to understand it better callback functions, setInterval, arrow function(()=>)

function offSetValue(){
     var scrollTop = (window.pageYOffset !== undefined) ? window.pageYOffset : 
    (document.documentElement || document.body.parentNode || 
     document.body).scrollTop;
}

setInterval(() => offSetValue(), 10);
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!