CC-00: Functions and Console Logs
with Carmen Salas • 2024/10/01
Code Challenge
In this code snippet, what is the argument and what is the parameter?
const sayHi = (name) => { return "Hi" + name }; sayHi("fellows");
ans: "fellows" is the parameter name is the argument
What is the difference between
console.logand thereturnstatement? In your response, be sure to answer the following:What is the purpose of
console.log?How is the
returnrelated to functions in JavaScript?
ans:
console.log's main purpose is to essentially see an output into the console. In other programming languages, this is whatprintwould be.Every function has a corresponding
return. It is implied to returnnullin occassions where it is not specified.returnby itself acts to terminate a function, and optionally hold a value along with it.
What is printed to the console, when the function
sayHiis invoked?
ans: fellows is printed when the sayHi function is invoked. The return value however, is "Hifellows".
Run this code in a file, what does the variable
helloevaluate to? Why does it evaluate to this?
ans: In the code above, hello evaluates into "hi", as a console.log output. However hello as a variable remains undefined.
What is the difference between
letandconst? What is the best practice when choosing which keyword to declare a variable with?
ans: let and const are similar in the sense that they are both keywords used to declare variables. The key difference is that let allows variable re-definition/assignment while const does not.
Last updated