About the "in" operator

Hi everyone!!

In today’s Ramón lesson Let’s learn data structures in JS! someone have asked if the in operator was a ES6 featured and we were not sure about it, probably ES5 I have said.

Correcting myself here: well I have found the in operator in the second edition (August 1998) of the ECMA-262 Standard (the link is an pdf archive where you will see it. You can open the pdf and hit Ctrl + F keys and search for “in operator”). So the in operator is old JavaScript feature wich exists before ES5 (ECMAScript 2009)!!

Related with the in operator and objects properties you might like to read this interesting MDN Web Docs articles: in operator, Object.hasOwn() and Optional chaining (?.).

I hope this is of interest to you and has help you on your way to achieve excellence in JavaScript.

P.S. For those who want to participate in the Class Central Forums and need some help with english syntax I recommend you this app Linguee dictionary and the related one DeepL translator. :smile:

4 Likes

Thank you so much, Carlos! This is fascinating!

2 Likes

I was wondering, based on what was said in the Q and A today about the difference between for (let… in…) and for (let… of…), maybe thinking of “in” as standing for “index” would be helpful. I’m not sure if this is stating the obvious. :slight_smile:

3 Likes

Nice mnemonic! :brain: :nerd_face: in for index!

2 Likes

Yeah @Jane2963637

Anything it works to remember it.

I think on it like this Are you IN this Barcelona JS Club or IN the original (prototype) Providence JS?, for example. Because in it checks if that property is an own property or inherited one from its prototype.

For check ONLY the own properties you have this method: Object.hasOwn().

And don’t use hasOwnProperty() anymore because as MDN have say:

Note: Object.hasOwn() is intended as a replacement for Object.hasOwnProperty().

Everything that will help to remember what JS syntax means is helpful, so thank you for sharing Jane!!

Happy day and coding!

2 Likes

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.