node.js - Nodejs variable value outside of the function -


in example i'm trying use variable outside of function no luck yet. guys can take , me solve issue? want use variable "value" outside of function.

var https = require('https'); var options = {   hostname: 'example.com',   port: 443,   path: '/values',   method: 'get' };  var req = https.request(options, (res) => {   console.log('statuscode: ', res.statuscode);   console.log('headers: ', res.headers);   res.on('data', (d) => {     var array = json.parse(d);     value = array[0][1];     console.log(value);   }); }); req.end(); req.on('error', (e) => {   console.error(e); }); 

there aren't tricks or overrides accomplish this. have plan have both places able see variable in same scope (you should read scope in javascript).

closures , classes can enable few other tricks playing scope, none allow override scoping rules entirely.

a "trick" can think of regarding scope using window in browser global object. can "hidden" variable - 1 that's in scope name has been overtaken local variable (or other variable closer in scope chain). again, design code , situations won't happen.


Comments

Popular posts from this blog

Capture and play voice with Asterisk ARI -

c++ - Can not find the "fiostream.h" file -

visual studio - Installing Packages through Nuget - "Central Directory corrupt" -