Javascript Cannot pass variable into feed code

I am trying to add a variable into a feed where it's expecting a string.

This works:

$('#theid').Timeline({
    feeds:  {
        'fb': {data: 'I want a variable here', limit: 10},

Open in new window


Now I am trying to insert a variable where is says 'I want a variable here'

So this is what I've done:

$(document).ready(function(){


        var myVar = 'my variable string value';


        $('#theid').Timeline({
            feeds: 
            {
                'fb': {data: myVar, limit: 10},

Open in new window


But this last one does not work...why?

How can I fix this?

Thanks
LVL 1
error2013Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Nothing wrong with that as the following example shows
<!doctype html>
<html>
<head>
<title>Test</title>
<style type="text/css">
</style>
</head>
<body>

<script src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	var myVar = 'my variable string value';
	var feeds = {
		'fb': {data: myVar, limit:10}
	};
	
	console.log(feeds);
})
</script>
</body>
</html>

Open in new window

But this last one does not work...why?

Does not work how? Error / not expected result?

Are there any errors showing in the Javascript console?

Do you have a link we can point to?
error2013Author Commented:
Log is giving me this error:

SyntaxError: missing } after property list
error2013Author Commented:
OK I found where the problem is.

If have the variable inside an if statement and the feed is outside that statement.

So variables in an if statement cannot be passed outside it?
Julian HansenCommented:
So variables in an if statement cannot be passed outside it?
Do you mean like this
	if (1==1) {
		var x = 5;
	}
	console.log (x); /* <== is this valid */

Open in new window


The above should work fine - however if you had this
	if (1==2) {
		var x = 5;
	}
	console.log (x);

Open in new window

You would get an undefined.

A syntax error for a missing '}' is something completely different though and has nothing (that I know of) to do with variable scoping

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.