Revising , I want better Understanding

Hello I am revising the JavaScript topics, I feel like I am getting to understand it better but before I go to the next chapter wich is Objects I want to understand everything better, so I am revising functions, arrays, loops and everything. I will post some questions here and I would appreciate the explanation, they may seem sometimes dumb but I really want to understand how things work. Sometimes will be enough just to point out where to start looking for the answer sometimes not. So Everybody feel free to enter with ideas, questions and answers.

Just in case you don’t know it:

Documentation serves as a great starting point for concepts, they give very clear examples:

There’s a great free book: It’s sometimes a little complicated for beginners but the examples are interactive and often useful.

And of course we’ll answer anything we can too.

1 Like

My first question as I was studying , is a bit weird, I know what happens but want somebody to confirm it so I can move on , sometimes self study-ing leaves you with doubts about your knowledge :sweat_smile:

As I was checking the Return Keyword topic we had this exercise/example:

function monitorCount (rows, columns) {
const numOfMonitors = rows * columns;
return numOfMonitors; };

console.log(monitorCount (5,4));

Of course , it will give me 20 as that will be the variables value and I am returning it

IF i delete the return numOfMonitors wich basically will mean I only store a variable in that block of code , and try to console.log it it will give me undefined. I would like to know why exactly it returns undefined? Is It still making the calculation and saves the value to the variable? And because I am not returning anything it gives me undefined? Or?
May be a dumb question , but I want to understand it better why things happen

Thank You @toastedpitabread , I use MDN sometimes , probably should use it more , but I am still in the learning phase, using Codecademy , FreecodeCamp, V School and a JavaScript course on Udemy. I only used MDN before to read on methods and properties , might not be a bad idea to look up concepts and read there also about what I learn. I have the eloquentjavascript book but did not started it yet, as I heard that it is not necessarily for beginners. Want to organize my studying schedule a bit better and then will include this book too in it

MDN is very useful in the learning phase (in my opinion). It may be helpful to try copying out their examples and trying to modify them to different situations.

1 Like

Another question. I am practicing the .reduce() method. I understand it how it works thats not a problem, but I wanted to try what happens if i just simply return the 2 parameters whitout adding them together.

const numbers = [1,2,4,7];
const sum = numbers.reduce( (sum1,sum2) => { return sum1,sum2});
when I console.log(sum) it gave me 7 - my question is Why?

I just want to see better when and why to use these methods?

It does return undefined-because you aren’t returning everything. The code inside the function is still running, there is just nothing being returned. undefined is a default value that is returned from anything that could return something, but doesn’t.
I hope this helps!


I have another question. I am learning about objects. And accessing with bracket notatio.
There was an example with the spaceship object that had 4 key-value pairs in it
And after that we declared a new variable returnAnyProp wich had an arrow function assigned to it with 2 parameters and the function returned objectName[propName]

In the explanation it says if we tried to write our returnAnyProp function with dot notation - objectName.propName - the computer would look for a key of ‘propName’ on our object and not the value of the propName parameter - can somebody explain why exactly?