Node.js vm.isContext() Method Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report The vm.isContext() method is an inbuilt application programming interface of the vm module which is used to check if the stated object is being contextified using vm.createContext() method or not. Syntax: vm.isContext( object ) Parameters: This method accepts single parameter object. Return Value: It returns true if the stated object is being contextified else it returns false. Below examples illustrate the use of vm.isContext() method in Node.js: Example 1: javascript // Node.js program to demonstrate the // vm.isContext() method // Including util and vm module const util = require('util'); const vm = require('vm'); // Assigning value to the global variable global.globalVar = 7; // Defining Context object const object = { globalVar: 3 }; // Contextifying stated object // using createContext method vm.createContext(object); // Compiling code vm.runInContext('globalVar *= 6;', object); // Displays the context console.log(object); // Displays value of global variable console.log(global.globalVar); // Calling isContext method vm.isContext(object); Output: { globalVar: 18 } 7 true Here, globalVar in the context is 18 in output as (6*3 = 18) but the value of globalVar is still 7. Moreover, here the stated object is being contextified so true is returned. Example 2: javascript // Node.js program to demonstrate the // vm.isContext() method // Including util and vm module const util = require('util'); const vm = require('vm'); // Assigning value to the global variable global.globalVar = 7; // Defining Context object const object = { globalVar: 3 }; // Displays the context console.log(object); // Displays value of global variable console.log(global.globalVar); // Calling isContext method vm.isContext(object); Output: { globalVar: 3 } 7 false Here, the stated object is not contextified so, false is returned. Reference: https://nodejs.org/api/vm.html#vm_vm_iscontext_object Comment More infoAdvertise with us Next Article Node.js vm.runInContext() Method nidhi1352singh Follow Improve Article Tags : Web Technologies Node.js Node.js-vm-module Similar Reads Node.js Constructor: new vm.Script() Method The Constructor: new vm.Script() method creates a new vm.Script object and compiles the stated code but it does not run the code. Moreover, the compiled vm.Script can run afterwards as many times as required. Here, the code is not connected to any global object, rather it's connected before each run 2 min read Node.js script.runInContext() Method The script.runInContext() method is used to run the compiled code which is present inside the vm.Script object within the stated contextifiedObject and returns the output. However, the running code has no access to the local scope. Syntax: script.runInContext( contextifiedObject, options ) Parameter 2 min read Node.js script.runInNewContext() Method The script.runInNewContext() method first contextifies the stated contextObject, runs the compiled code inside the vm.Script object within the context created and then returns the output. However, the running code has no access to the local scope. Syntax: script.runInNewContext( contextObject, optio 3 min read Node.js | script.runInThisContext() Method 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 m 2 min read Node.js vm.createContext() Method The vm.createContext() method is used to create a single context that can be utilized to run more than one scripts. Moreover, if the stated contextObject is neglected then a new, empty contextified object is returned. However, if contextObject is stated then, this method will ready that object so th 2 min read Node.js vm.runInThisContext() Method The vm.runInThisContext() method compiles the code, runs it inside the context of the current global and then returns the output. Moreover, the running code has no access to the local scope, but have access to the current global object. Syntax: vm.runInThisContext( code, options ) Parameters: This m 2 min read Node.js vm.isContext() Method The vm.isContext() method is an inbuilt application programming interface of the vm module which is used to check if the stated object is being contextified using vm.createContext() method or not. Syntax: vm.isContext( object ) Parameters: This method accepts single parameter object. Return Value: I 2 min read Node.js vm.runInContext() Method The vm.runInContext() method is used to compile the code. It runs the code inside the context of the contextifiedObject and then returns the output. Moreover, the running code have no access to the local scope and, the contextifiedObject object be contextified formerly using vm.createContext() metho 4 min read Node.js vm.runInNewContext() Method The vm.runInNewContext() method contextifies the stated contextObject, compiles the code written and runs it inside the context created and then after all this returns the output. However, the running code have no access to the local scope. Syntax: vm.runInNewContext( code, contextObject, options ) 5 min read Like