Below Node.js code if I run that on other places it works well, but in VS Code it throws an error.
this.k= 8
TypeError: Cannot set properties of undefined (setting 'k')
at subfun (file:///c:/Users/Administrator/Documents/2.js:3:15)
at mainfun (file:///c:/Users/Administrator/Documents/2.js:6:5)
at file:///c:/Users/Administrator/Documents/2.js:8:1
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
at async loadESM (node:internal/process/esm_loader:91:5)
at async handleMainPromise (node:internal/modules/run_main:65:12)
My code:
var mainfun = function (){
function subfun(a){
this.k= 8
console.log(this.k)
}
subfun()
}
mainfun()
Need the above solution to run on VS Code and I'm looking for an error reason.