Struggling to understand documentation on MDN

I’m beginning to really enjoy learning JavaScript and feel like things are starting to ‘click’. However, when trying to solve problems on my own and looking up information on MDN I find some of the terminology and phrases used complicated and therefore hard to grasp. Is this normal for a beginner and does anyone have any advice on how to improve my terminology and become better at reading documentation? I was just looking up .valueOf() Object method and have no understanding of some of the terminology… e.g. primitive value, prototype?

I have also found myself often thinking… yes I understand the syntax here but what is actually happening under the hood. Why does the code behave in this way. Do you have any recommendations for how I can understand better why things works? Hope that makes some sense. Thank you

1 Like

Hi, I get it. As a beginner myself sometimes the documentation on MDN seems too complicated. What helps me usually are the Demos and Examples. Playing with the demo of a documentation assists me with the “under the hood” understanding, as you described, and the examples sometimes contain simpler instances and useful comments.

If I really get into trouble with the terminology and everything else I just use google, usually there is a simpler explanation on another site or YouTube video, Good luck :smiley:

2 Likes

So let’s look at the example (with added commentary in the comments):

function MyNumberType(n) {
  this.number = n;
  // n is assigned to this.number but is not returned. it's just a property of MyNumberType
}

// Without .prototype.valueOf, object1 can't be added to 3, because it's an object 
// and there's nothing actually accessing the property this.number's value, which here is 4
MyNumberType.prototype.valueOf = function() {
  return this.number;
};

const object1 = new MyNumberType(4);

console.log(object1 + 3);
// expected output: 7

That code functions the same as:

function MyNumberType(n) {
  this.number = n;
}

const object1 = new MyNumberType(4);

// This time we accessed the .number property directly without .prototype.valueOF
console.log(object1.number + 3);
// expected output: 7