CC-00: Functions and Console Logs
Last updated
Last updated
with Carmen Salas • 2024/10/01
In this code snippet, what is the argument and what is the parameter?
ans: "fellows"
is the parameter name
is the argument
What is the difference between console.log
and the return
statement? In your response, be sure to answer the following:
What is the purpose of console.log
?
How is the return
related 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 what print
would be.
Every function has a corresponding return
. It is implied to return null
in occassions where it is not specified. return
by itself acts to terminate a function, and optionally hold a value along with it.
What is printed to the console, when the function sayHi
is 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 hello
evaluate 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 let
and const
? 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.