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


14,136 Points

Basic Javascript questions

I've just finished the 2 first JS introductory courses and have a few questions after doing those, which it would be good to understand:

1) Parameter vs Argument. The courses mentioned both - what's the difference is their a difference. Is the parameter the variable used to copy the argument passed to the function?

2)Literal -string literal, array literal, what does literal mean. I first thought that was an empty version of the object, but it doesn't seem to be. Is it a constant version?

3)Objects/Dictionaries (used to python). JS objects look like python dictionaries but they appear to only allow strings as keys and aparrently they aren't implimented as a hashtable? What does mean (vs python) in terms of their use or limitations?

4)Anonymous functions - Anonymous functions seem to be used a lot in JS. I'm not sure what the benefit where they are just used once - (why bother to have a function) - are they used to have a separate namespace instead? eg(from Jquery course)

  //3.1, Show spoiler
  $(".spoiler span").show();
  //3.2, Get rid of button


1 Answer

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

Hi there. I can help you out with a few of those. :)

1) In functions a parameter is a placeholder variable (or even if you want; a placeholder value) which you declare at the function definition. So you can give a variable name inside the parentheses which you can use to perform an action.

function addition (paremeter1, parameter2) {}

An argument, is the value you're passing into the function that makes use of those parameters.

So you could pass in a 2 numbers at the function call that gives the values you want to work with.

function addition (parameter1, parameter2) {

var adding = parameter1 + parameter2

addition(4, 5)

So the last line, passes in the numbers 4 and 5 which allows the function to add the values together.

2) To me an array literal just means the syntax for making an array in JavaScript (and other languages)

A string literal is just another word for a string, i.e. var string = "This is a string";

3) With an object, you can store any type of data as a value. You can even store functions as values or have an object, within an object. I don't think there are many, if any limitations. :-)