VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-script-runinthiscontext-method/

⇱ Node.js | script.runInThisContext() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js | script.runInThisContext() Method

Last Updated : 2 Apr, 2020
The script.runInThisContext() method runs the compiled code present inside the vm.Script within the context of the current global object. Moreover, running code has no access to local scope, but it has access to the current global object. Syntax:
script.runInThisContext( options )
Parameters: This method accepts single parameter options which is optional and returns Object. The options can be displayErrors, timeout, and breakOnSigint. Return Value: It returns the result of the very last statement executed in the script. Below examples illustrate the use of script.runInThisContext() method in Node.js: Example 1: Output:
I am an author?
Example 2: Output:
57
Reference: https://nodejs.org/api/vm.html#vm_script_runinthiscontext_options
Comment

Explore