Thank you kindly for your patience. I know I’m asking a lot of questions and me struggling can be frustrating at times but I really am doing my best. I find the point of entry to be very high. New definitions relating to terms I’m not familiar with which makes it labyrinthine to figure something out.
This being said, back to business.
Sometimes people call everything a keyword instead of using a more precise word.
Which in itself is problematic for me. There’s so much jargon to sort through and a slight imprecise understanding of the concepts makes it increasingly harder to understand what’s being explained. I feel like some terms can be freely interchanged while others should be strictly used.
No it does not, as has already been explained. Sometimes people use terms without really thinking about what the term really means and if a constant were to be called a variable then they would be wrong. Think about the word variable . As has been explained, a constant is not variable.
The way I understood it when I did the exercise, all three let
, var, and
const, could be used interchangeably to declare variables. On the MDN website, const
is listed along var
and let
, both of which are used to declare variables. This let me to believe, mistakenly, that it was part of the group for lack of a better word. The syntax expressions used to declare variables.
Now the question comes to mind, since const
is not used to declare variables, what is used to declare then?
Going back to my previous screenshot. It’s clearly categorized as syntax word meant to declare something. What can you declare besides a variable?
So before asking any further questions, I did my own research. According to this website:
Here’s what I infer from reading this sentence: variables defined with
const
… means
const
is used to declare variables just like
let
and
var
are except they cannot be reassigned. Which brings me back to:
Because variables are… variable. And constants are… constant.
Even though constant are constant, they’re still used to declare variables. This is where I think we misunderstood each other. So I was right to say that const
are used to declare variables. I was puzzled by this citation as I clearly misunderstood what it was meant to say. My misunderstanding of this sort of led me astray a bit.
And so back to my original question (I’ll limit my questions to one a piece):
Why is it that they say they’ve defined a function logSkyColor()
?
As I’ve already established, let
, var
and const
are used to declare variables. Perhaps what m_hutlet meant by saying variables were variables was that they could be many different things. So let’s do some research about variables.
A variable is quote:
A variable is a named location for storing a value. That way an unpredictable value can be accessed through a predetermined name.
From the get go, I figured values for variables could only be primitives which could have been a wrong assumption on my part.
We know what variables come with an identifier or what I’ve personally called keyword in the past. From what I understand they mutually interchangeable or synonyms when it comes to computer syntax.
If I go back to:
logSkyColor
is the identifier. So far so good.
From here, we know that a variable can doesn’t only hold primitives, they can hold functions as well. So a variable can hold both functions and primitives.
Let’s carry on. Back to my exercise:
So we can see there’s another variable in the code block of const
. But we also see the arrow notation which is likely why const
is called a function here.
Then boom! While doing research I find it, what I had been looking for:
So a variable which refers to a function stops being a variable declaration but is instead refers to a function.
Which comes back to my own question: why is const
here called a function? The answer is because the variable declaration refers to a function.
The reason why I’m saying const
refers to a function is because of the arrow => notation.
According to this:
are a more concise syntax for writing function expressions
So function expressions, what are those? According to this:
So a function expression is when a function is stored in a variable just like… here:
Which means here, this is a function expression, not just a function declaration.
Now that this is settled, let’s carry on. We were talking about the arrow notation which is used in function expressions.
When it comes to arrow notations, we find out that:
.
That is to say both function
and return
are implied in the arrow notation, also called ‘fat arrow’.
Normally with a variable I’d have the parameters in between my brackets, if any.
Anyhow, in the second step of the exercise, I’m told:
Here by ‘within’ I interpret that they want me to have the variable declaration within the code body { }. And so I type something like this:
which works for step 2.
Step 3 doesn’t come as a challenge to me:
which I easily clear:
Step 4 doesn’t come as a challenge either:
As all in all I managed to make it with plenty of research and I’m patting myself on the back .