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 trialNimesh Joseph
905 PointsHow can we store numbers inside a variable in javascript??
is there special type of variable for that??
7 Answers
Lush Sleutsky
14,044 Pointsvar variableName = number; ...is the way to store a number, just like any variable
var myNumber = 17;
Simple as that!
Lush Sleutsky
14,044 PointsTurns out that "name" is a reserved word...
Lush Sleutsky
14,044 PointsI 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...
Nimesh Joseph
905 Pointsbut 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??
Nimesh Joseph
905 PointsThanks for helping me out .
Nimesh Joseph
905 Pointsbtw can you just tell me how you display your code inside that black box. I am new to treehouse forums
Lush Sleutsky
14,044 PointsClick 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...
Nimesh Joseph
905 Pointsoh thank you!!!