FAQ: Functions - Parameters and Arguments

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.

Hey!

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

Hello

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?

Thanks,

Hey, @micro7957614922 welcome to the forums.

You cant do this because Cole is not a data type. You would need to make it a string because that is a data type.

Thanks! So, just to make sure I have it clear, template literals can be used to concatenate any known data type value as a string, but because Cole in this case has no data type yet it cannot be done as such?

1 Like

Yes because Cole but if you put 5 instead it would work because it is the number data type. You can view the entries for general data type and for JS data types.

Thanks, appreciated!

'Thank you for your purchase '+ name + ‘! We appreciate your business.’

The only thing I don’t quite grasp is why the + must be within the single quote.
In past exercises doing string concatenation the + were not inside the quotes.

Can someone explain why?

Hey, welcome to the forums!

I’m not quite sure what you mean here, would you mind clarifying please: the two strings themselves are in quotes, but the + (and the variable) are not :slight_smile:

That’s correct, it shouldn’t be

1 Like

AHHHH, i see what you mean now. I was looking at this wrong.
I was looking at this as if only name was in quotes. I see exactly what you mean now.

Thank you

1 Like

No problem, happy to help :slight_smile:

Thank you for asking this rishabhkaul, and thank you for your response victoria-dr! I did the same thing with trying to declare Cole as a variable in step 3, and I now understand what I did wrong here and how to fix it.

hey! quick question… for the example of passing an arguement/paramater through a function, my code looks like this:

function sayThanks(name) {
console.log(Thank you for your purchase, ${name}! We appreciate your business.);
}

sayThanks(“sarah”);

in the example, it wants me to do it a different way, like: ’ + name +’ , and it wont let me progress. is my code correct? would i end up with dependency/scope issues down the line if i did it my way? idk why it says it’s “wrong”…