FAQ: Functions - Parameters and Arguments

I think a lot of the quetions here about declaring variables and or values in functions are jumping ahead of the lessons. At this point, the lesson is merely familiarizing us with the concepts of functions. In later lessons the confusion is cleared up in the use of particular arguments and how/when they are to be used.

Some people like to take small steps in learning and some like bigger steps. There is no way to cater to everyone, but all in all it is easier to learn one piece of the code at a time.

Just MO :slight_smile:

does the variable used as a parameter in a function declaration be declared before the function?

No, the parameter is as declared as it needs to be, and it has local scope, only. Remember it is just a placeholder for the expected argument in the call expression.

1 Like

Thank you for your reply. I am new to this and just found out the question I asked has been raised before. Lesson learned : do a search first. Hi, hi. Again thank you for your response.

1 Like

I’m pretty sure I did this right but it is not allowing me to pass the lesson? Any help?

function sayThanks(name) {

console.log('Thank you for your purchase '+ name + ‘! We appreciate your business.’);


const name = “Cole”


Do the instructions ask us to return a value from the function?

Yes I figured it out. The instructions were a little confusing and not explained well that you put the value in the parenthesis

1 Like

Okay, why is codecademy showing the solution in double quotes but it says to copy and paste the message in single quotes? ’ vs. "

It shouldn’t matter in most cases. The occasional SCT requires one or the other, but that is a simple oversight by the author.

inside a function, every line of code should end with semicolon?
I know in JS isn’t strictly necesary the use of semicolon to end a line, but what if I asumming that code styling?

Thanks in advance!

Knowing when to use them and when not to is part of the primer of JavaScript. Ignore at one’s own peril.

1 Like

Thanks for the comment! So, do you recommend use in every line for the moment (I mean, just in case)?
I’m a beginner, and I hope the experience will give me the answer.

NP Truth is, in modern browsers the JS engine will fill in the missing ‘end of statement delimiter’. The problem comes down to minifiers. These programs collapse code by removing unnecessary white space. Line breaks are white space so they are included. This converges code into something that might be unintelligible to the interpreter, so will be lost code if it doesn’t throw an error. The correctly installed semi-colon (by the developer) will have prevented that.

Consider what defines a statement. Think in terms of in line. Even though an if..else is a statement, it is also a construct, it comprises of code blocks that are only open to a certain condition. The blocks contain statements. Owing to the construct nature of an if statement, the braces are the delimiters and ending them with a semi-colon would be moot, and superfluous.

1 Like

Cristal clear :ok_hand: Thanks!

1 Like

In this sayThanks exercise, step #2, the code is given in single quotes. I have decided I want to use double quotes for two reasons: be more easily distinguished from back ticks and I won’t have to remember special occasions when using the single quotes. If you check the hint, double quotes are used. However, if my input into the editor is double quotes, the step is marked with a red X. Appreciate your input.


Sometimes Codecademy can be extremely fussy with how they mark exercises, so even something like using a different kind of quotes is enough for it to be marked incorrectly, even with perfectly valid code. Would you mind sharing your code (formatted according to this) and a link to the exercise :slight_smile:

Unfortunately, Javascript does not support static typing. At least out of the box, if you want static typing you should use TypeScript

1 Like

how does the function know that the input should be treated as a string? should we declare data type of a function’s parameters somewhere in the code?

like I said, static typing is not possible in Javascript. Which means you either need to validate the parameter type at run time or use TypeScript (which allows us to use static typing in JavaScript)

1 Like


Why can I not simply pass Cole as an argument rather than “Cole” when I use a template literal in the function. For example

Isn’t the point of template literals to force the variable to be passed and concatenated as a string, or did I misunderstand the previous lesson?