---
title: "Comment by Victor Souza on \"A Brief History of JavaScript Part 2\" | Hashnode"
description: "If you call a property/method and it doesn&#39;t exist, it returns undefined: const myObject = { city : &quot;Madrid&quot; , greet : function ( ) { console .log"
url: "https://hashnode.com/posts/a-brief-history-of-javascript-part-2/6235668dbef4c71aa6f0f758/comment/6237c552bef4c71aa6f12eae"
---

[Discussion](https://hashnode.com/posts/a-brief-history-of-javascript-part-2/6235668dbef4c71aa6f0f758)

Comment [A Brief History of JavaScript Part 2](https://hashnode.com/posts/a-brief-history-of-javascript-part-2/6235668dbef4c71aa6f0f758)

[Victor Souza](https://hashnode.com/@victor0x16)

[Mar 21, 2022](https://hashnode.com/posts/a-brief-history-of-javascript-part-2/6235668dbef4c71aa6f0f758/comment/6237c552bef4c71aa6f12eae)

If you call a property/method and it doesn't exist, it returns undefined:

```
const myObject = {
    city: "Madrid",
    greet: function () {
         console.log(`Greetings from ${this.city}`);
    }
}

myObject.greet(); // Ok: Greetings from Madrid
myObject.country; // undefined
```

However, the prototype chain ends when null is found:

```
Object.prototype // null
```

That is a little weird for me, but I got it :)

[Adib Hasib](https://hashnode.com/@adibHasib), thanks for the great post. I was studying it today so its nice to read it here ✨🎉

[Adib Hasib](https://hashnode.com/@adibHasib)

[Mar 21, 2022](https://hashnode.com/posts/a-brief-history-of-javascript-part-2/6235668dbef4c71aa6f0f758/comment/6237c552bef4c71aa6f12eae#reply-6237f6078e4fae3f767e0617)

You got that right. Whenever we try to access an object property that doesn't exists, we get `undefined`. So we can use this feature to check if an object property exists or not. For example,

```
let str = "The quick brown fox"
let freq = {}

str.split("").forEach(char => {
    freq[char] === undefined ? freq[char] = 1 : freq[char] += 1
})

console.log(freq)
```

This little piece of code makes JS objects behave like hashmaps and count the character frequency in the `str` string.
