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

125
Views
How do I change dev tools console scope to be local to a function?

How do I use Chrome dev tools to evaluate code within the local scope of a function? I.e. for the following code

const name1 ="alireza"

function person(){
    const name2 ="joe" 
}

the result of code manually executed in the console should be

console.log(name2) //"joe"
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

This is slightly tricky because the statement you want to examine is the only statement in the function.

If you were to add another statement on the following line:

const name1 ="alireza"

function person(){
    const name2 ="joe" 
    const name3 ="bob";
}

Then you could:

  1. Open the Debugger tab
  2. Create a break point on the line after const name2 ="joe"
  3. Open the Console tab
  4. Type person() to run the person function
  5. Wait for the breakpoint to be hit
  6. Return to the Console tab
  7. Type console.log(name2); (or you could just look at the debugging information in the Debugging tab which reports all the in-scope variables).
about 4 years ago · Juan Pablo Isaza Report

0

What you are looking for are breakpoints:

You can dynamically set a breakpoint on a line within the function you want to inspect: devTools will break before the execution of that line and you can evaluate code within the scope of that function in the console.

Alternatively - if you can change the code (which you can also from devTools) - you can put a debugger statement where you want the execution to break.

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!