JavaEvgen JavaEvgen - 1 year ago 88
Javascript Question

How to pass variables to a method inside a fuction JavaScript

My code looks like this:

var getData = function(section, sort) {
var url = '' section '+/+' sort '+/1'
url: url,
method: 'GET',
headers: {
'Authorization': 'Client-Id xxxxxxxxxxxxx'
}, function(e, r, body) {
var metadata = JSON.parse(body);
getData('hot', 'viral');

I'm sorry for the last part of the code, for some reason I couldn't make it better here.

My problem is that I wan't to firstly ask for search parameters(section, sort) and then use them in my url inside req.get method. Compiler gives me some:

var url = ''section'+/+'sort'+/1';
SyntaxError: Unexpected identifier
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3

I'm new to Node and JavaScript, please don't blame me. Thank You in advance!

Answer Source


var url = '' section '+/+' sort '+/1'


var url = '' + section + '/' + sort + '/1';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download