Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Introduction to Programming Basics Variables

How can we store numbers inside a variable in javascript??

is there special type of variable for that??

7 Answers

Lush Sleutsky
Lush Sleutsky
14,044 Points

var variableName = number; ...is the way to store a number, just like any variable

var myNumber = 17;

Simple as that!

Lush Sleutsky
Lush Sleutsky
14,044 Points

I don't know why it does that to tell you the truth, but if you call your variable something other than name, it works. Actually quite strange...

var anyVariableName = 12;
console.log(anyVariableName + 4);

will print 16 to the console, but with var name, it will concatenate them. Not sure why. As far as I know, name is not a reserved keyword or anything...

but when i used this code

var name=12; console.log(2+name);

the console is displayin 212 instead of 14. But when I use any other operator instead of '+', the answer is correct. Why is that so??

Thanks for helping me out .

btw can you just tell me how you display your code inside that black box. I am new to treehouse forums

Lush Sleutsky
Lush Sleutsky
14,044 Points

Click on the "Markdown Cheatsheet" link, which is right under the box you use to make posts, and it will tell you how to do it...

oh thank you!!!