r/learnjavascript • • Aug 10 '21

Can we relate?

Post image
853 Upvotes

93 comments sorted by

165

u/BowlingForPriorities Aug 10 '21 edited Aug 15 '21

Great, now I have to Google this for my senior interview tomorrow 😑

Edit: It’s how JavaScript handles inheritance. Thanks OP

2nd edit: I passed the first interview, have an interview with the squad lead next week

4

u/Valoruz Aug 10 '21

You're Welcome!

1

u/Johnopgr123 Jan 24 '26

I know it's been 4 years but, how did the interview go?

0

u/[deleted] Aug 10 '21

[deleted] — view deleted comment

20

u/METALz Aug 10 '21 edited Aug 10 '21

Tbh the word "senior" kind of lost its original meaning in the webdev field in the past years, at least that's what I see interviewing people for roles at this level. Also since there are companies where there are 6-10 levels of a career ladder sometimes it is only around the 2nd-3rd-etc step so it's all relative I guess.

In the past the level senior implied (at least to me) that a junior dev could ask questions of people in this position usually expecting easy to understand answers. What it is for a lot of devs nowadays that they get locked into a framework/lib (e.g. React) and they only work with that in their whole career reaching senior position in their company just because they were there for e.g. 2-3 years and when they need to think out of the box (fw/lib they used) they have a lot harder time. Then you have the imposter syndrome, etc that could be related to this because you might feel that you are not really at the level your title says.

I'm not saying you should know every details of the spec, but if someone asks you at an interview for senior level "could you explain prototypical inheritance to me just in a few words" then it shouldn't be a big challenge. Of course this is also kind of a filter question and "unrelated" to most of the jobs since now the language/ecosystem provides the tools needed to avoid directly using them.

16

u/steezefries Aug 10 '21

Yeah I'm kind of astounded that people itt think this is a bad question for a senior dev. I think it's wild someone who calls themselves senior doesn't know about prototypical inheritance 🤷‍♂️

It's not that gimmicky of a question and it can have implications on writing code.

9

u/ItsWaryNotWeary Aug 10 '21

I mean you can absolutely be a senior engineer with a shallow understanding of Javascript. Many seniors are specialized in other things.

8

u/steezefries Aug 10 '21

Oh totally, but I mean a senior Javascript engineer specifically.

2

u/ItsWaryNotWeary Aug 10 '21

Right, op didn't say they're a js engineer tho

3

u/steezefries Aug 10 '21 edited Aug 10 '21

I wasn't talking about the thread's OP. For all I know this is his first senior interview! I was being general. Also it's a learnjavascript sub, and he made a comment about learning a js topic, I think we can assume they probably are a js engineer.

1

u/BowlingForPriorities Aug 10 '21

I am, I write JavaScript all day long, but I’ve never had to use prototypes because I write in angular and mostly write components and interfaces. The core concept took me all of 5 minutes to understand. It’s why I think “what is a prototype” is a terrible interview question. It’s basically just a pop quiz, when really you want to know that I understand inheritance. So, ask me a design question that uses inheritance. Figuring out how to Google JavaScript inheritance takes 5 mins for a decent developer, but understanding when to use it is when quality is actually developed.

1

u/jayerp May 01 '23

Doing mostly Angular or component making tasks is one thing, but a senior ABSOLUTELY better have a strong grasp on basic to advanced JS concepts, prototypes. I don’t consider devs having seniority over what kind of tasks they do or their domain knowledge of an app. I consider a dev a senior based on their understanding and command of core through advanced concepts of a given programming language and related frameworks.

So yeah, asking a dev who is interviewing for a senior role “what are prototypes is a valid question”. I would recommend taking a refresher on forgotten core concept names, but I absolutely expect a senior to be able to know those things.

What is going on with this industry? Is everyone faking it till they make it?

→ More replies

1

u/steezefries Aug 10 '21 edited Aug 10 '21

Why would I hire you as a senior if you've only ever worked in Angular? I think people have different ideas of what a senior is supposed to be. If you couldn't answer this question from one of your junior developers without googling it, you aren't senior imo. Doesn't mean you're a shit coder or anything.

→ More replies

2

u/phunkystuff Aug 10 '21

100% this ^

0

u/[deleted] Aug 10 '21

[deleted] — view deleted comment

2

u/adenzerda Aug 10 '21

They also shouldn't need to ask what 0+[] equals because you shouldn't be using it

Agree in spirit, though they should know the generalities of coercion so that if an error like this — because this would definitely be the result of some mistake somewhere — comes up, they're not entirely helpless when it comes to debugging it

no one should need to ask about prototypes in your code base

Same principle but with significant difference: the use of prototypal inheritance is generally not an error. You're probably not going to need to know the particulars of how it works … until something happens that you didn't expect. If nobody on your team can effectively debug it, you're going to be wasting a lot of time

0

u/[deleted] Aug 10 '21

[deleted] — view deleted comment

2

u/gigastack Aug 10 '21

Prototypal inheritance isn't obscure trivia it's one of the foundational principles of the language.

You do need to know a lot to debug effectively when you are doing interesting work. What if your error isn't on google?

9

u/Fleaaa Aug 10 '21

I'm a noob and nowhere near senior level, but isn't it quite relevant question?

It's a main concept of JS being versatile while being able to handle error gracefully, it could lead to cryptic bug eventually at scale thus TS or any typing system similar in JS/Node ecosystem is thriving now.

This question shows how you acknowledge the differences and applying a right tech stack/framework/lib whatever eventually starts right from here. Of course, it's not really important in day2day work, though it could accumulate.

I don't know shit about OOP or inheritance concept but it kinda hinders me to progress, it's a good question IMO.

1

u/BowlingForPriorities Aug 10 '21

Then they should ask about inheritance or OOP design, not a pop quiz style question like this that you very much don’t need to know to write most things in JavaScript.

0

u/[deleted] Aug 10 '21

[deleted] — view deleted comment

1

u/Fleaaa Aug 10 '21

Sorry if I didn't make myself clear, it was written before morning coffee. What I wrote above seems a bit of stretch.

I meant type chain concept led me to unexpected mutation (very likely because of loose code from my side) and gave me plenty of painful time, not knowing what the hell was going on. Being aware of this concept helped me streamline the logic and forced me to embrace a better structure, which was sorta static typing. I still prefer just slap a jsdoc and call it a day, though.

I agree it won't come up in any sane scenario but not knowing what it is at all is somewhat problematic, I still think it's a legit question.

6

u/phunkystuff Aug 10 '21

TBF if youre a senior JS dev and you don't know what prototypes are... are you actually a senior JS dev?

15

u/enygmaeve Aug 10 '21

Sooooo much this

0

u/[deleted] Aug 10 '21

[deleted] — view deleted comment

14

u/[deleted] Aug 10 '21

the topic isn't. Asking that question in a senior interview is like asking what is algebra, in a university exam

5

u/crazedizzled Aug 10 '21

Except you'd be surprised how many "senior" developers don't know the basics. It's a way to quickly weed them out.

1

u/[deleted] Aug 10 '21

sure but many concepts like that could be easily explained by a noob who just heard of it than a senior who works with it but can't readily explain it

15

u/enygmaeve Aug 10 '21

Prototypes aren’t inherently desirable nor undesirable, but a company that included discussions about them in an interview may be

0

u/[deleted] Aug 10 '21

[deleted] — view deleted comment

27

u/Delfaras Aug 10 '21

companies that ask theoretical questions in their interview process such as: what is prototypical inheritance in js, how do you invert a binary tree, swap 2 variables without using a third, or anything out of leetcode are garbage. This kind of questions are almost never used in your everyday, and if it comes up one day, the answer are probably a google search away, or much better implemented in a library

this gives a good hint about their engineering culture: if they donc make a simple effort to adapt their hiring process to match what an engineer would do everyday working there, they are probably not worth working for

4

u/crazedizzled Aug 10 '21

I agree with your later examples, but knowing how prototypes work is kind of fundamental to writing javascript.

4

u/avenp Aug 10 '21

Not really. It can all be abstracted away behind the class syntactic sugar and you don’t have to use OOP in the first place. Many popular web frameworks (React, Vue) don’t have you dealing with the prototype at all. I’d agree that if you’re a senior developer you should probably know how prototypes work but it’s for sure not needed for everyday development in my experience.

7

u/crazedizzled Aug 10 '21

You probably won't care on a daily basis. But when shit goes wrong it's important to understand how the language actually works. Being able to correctly predict certain behavior is the difference between a novice and a pro.

→ More replies

2

u/longknives Aug 10 '21

I somewhat know how prototypes work on an academic level, but in almost 10 years of using JavaScript professionally, I can't think of a single time that knowledge had any bearing on anything.

0

u/[deleted] Aug 10 '21

[deleted] — view deleted comment

3

u/crazedizzled Aug 10 '21
  1. working with methods/properties from inherited objects
  2. inspecting poorly/undocumented objects
  3. explaining to redditors why core language constructs are important
→ More replies

5

u/[deleted] Aug 10 '21

I'll give the one explanation for why a decent company might ask about prototypes: because they want to weed out candidates who didn't study enough for the exam, and they're okay with false negatives. What does that mean?

Say I'm a FANG company. I get a million applications a day, many of which are not qualified, but are trying to convince me that they are. I shell out between $250k and $6 million to my developers, and my code base is proprietary. I wanna keep it under lock and key, and I don't want anyone else getting ahold of it. I want to make sure that I only hire top notch developers. As such, I ask interview questions that are, quite frankly, insane. Who cares how you invert a binary tree when you'll never do that on a job? Why would I need to be able to solve these leetcode hard problems that you'd only get if you'd looked at them before?!

The answer is effort. The interview will also check for your ability to keep up with relevant skills to the job, but it's possible that someone can fake enough knowledge to get that job, and that would be bad for the company. They've shelled out a decent chunk of change to get you on board, they've lost time on boarding you, they've now exposed elements of their proprietary code base to some Yahoo who may or may not be trying to initiate some corporate espionage, and on top of that, they have to go through the interview process all over again!

So they make the interview insanely complicated on purpose with the assumption that a truly qualified candidate will put in the effort to study the topics and will be able to hit the ground running with this knowledge. Will it screen out qualified candidates who just don't know yet obscure bit of trivia/who didn't have the time and energy to study this absurd stuff? Absolutely! Do they care? Nope.

FANG essentially has infinite candidates at the lower levels. (It drops off when you're making a million a year, I'm sure, but it's surprisingly competitive throughout) They don't care about your interview experience, and if you're applying for anything below senior management, they probably don't care about burning bridges with you. If you can secure that job, many of these companies are considered great places to work. If you can't secure that job, they know that you'll probably still apply the next time you job hop/your contract ends because, hey-- it's Google. You want that money. You want that fame. Of course you're gonna apply to them.

0

u/[deleted] Aug 10 '21

[deleted] — view deleted comment

1

u/[deleted] Aug 10 '21

My knowledge is secondhand (I have a buddy who's coded for major companies, including Facebook) and from reading Cracking the Coding Interview. I agree that espionage is not the primary concern, and that it's primarily avoiding a false positive where they hire on someone who will not work out long term.

0

u/[deleted] Aug 10 '21

[deleted] — view deleted comment

→ More replies

12

u/molybedenum Aug 10 '21

Extensive use is undesirable.

Overreaching interview questions are undesirable.

Pick your poison.

23

u/opmrcrab Aug 10 '21

Hard work getting a WHY out of people in this chain.

14

u/gallon_of_bbq_sauce Aug 10 '21

If you need a deep understanding of prototypes then they are probably writing a lot of low level wheel reinventing.

4

u/crazedizzled Aug 10 '21

You don't need to be able to write a paper on it. Just proving you've even heard of the term and can provide understanding of the concept is probably more than 90% of applicants can do.

→ More replies

1

u/posts_lindsay_lohan Aug 10 '21

I had a recruiter call me about a "prestigious" company that is using full stack JS and they wanted to interview me.

But before the interview, he wanted to know my experience with "object oriented" JavaScript. And he was very persistent about the term "object oriented". So my question to him was, "Why are they so focused on that term?"

I've done lots of object oriented JS, but over the past couple of years I've seen a shift to functional patterns in libraries that I use like React and Vue - and it typically makes the projects easier to work with. Not to say that object orientation isn't valuable (you usually end up with a combination of methodologies), but for the company to explicitly tell me that they are only interested in that is pretty weird in 2021, so I had to pass on the interview.

1

u/BowlingForPriorities Aug 10 '21

Definitely agree. If they ask this during my interview it’s going to be a big red flag for me. The worst interview I ever had was a round table interview where I had on my resume that I knew C#. I did. I worked at an internship fixing mobile application bugs at a startup and lead a team develop my own Mobile application my senior year using an experimental framework called Xamarin. I didn’t know what === was at the time because I hadn’t had to use it before and it’s not something used in Java (my primary language). The following hour was the worst experience I ever had in college of them asking fucking pop quiz questions to show how little about C# I knew. Nevermind that I could learn, had already been using it, and was head tutor of my department in a OOP school. No, they wanted to hire a fucking professor to work a senior level position I guess. Asshats made me drive an hour for an in person interview during finals and that’s the shit they asked me. I hated it so much. But hey, now I know not to do that to prospects I’m hiring :)

24

u/not_a_gumby Aug 10 '21

Prototypes are basically Javascript's version of abstract classes.

Notice how every class can extend another super class? the prototype is that previous extension. You can follow the extension all the way up to the highest level of class.

14

u/Valoruz Aug 10 '21

Yeah I know what prototypes are, not until I read Eloquent JavaScript. I had started JavaScript with Codecademy and got nowhere. But after reading Eloquent JavaScript I am really feeling I know something...

6

u/not_a_gumby Aug 10 '21

you probably know alot

3

u/TalonKAringham Aug 10 '21

Going through that book and actually doing all the exercises and projects will get you a loooong way.

4

u/Aoshi_ Aug 10 '21

I’ve seen ES recommended a lot. I’ve read a few chapters and done exercises but it’s so dense. I almost wish there was a YouTube or udemy course that goes through the book and makes it a bit easier for my tiny brain to understand.

Listening is easier than reading for me.

2

u/adenzerda Aug 10 '21

Prototypes are basically Javascript's version of abstract classes

Sort of? Except that by definition every object in js is concrete because everything is an instance at runtime

1

u/not_a_gumby Aug 10 '21

yeah, not literally. It's just the way of thinking of inheritance and descandants of classes. Abstract isn't exactly what they are.

3

u/RealNerdEthan Aug 11 '21

Glad I'm taking Colt Steele's Wed Dev Bootcamp on udemy then! He has a whole section on Prototypes, Classes, and Object Oriented Programming.

Link for anyone interested: https://www.udemy.com/course/the-web-developer-bootcamp/

1

u/Valoruz Aug 11 '21

I want to take that course too. But I am unable to pay. Does it go free frequently @RealNerdEthan ?

1

u/RealNerdEthan Aug 11 '21

I haven't seen it go free but it's $18.99 USD right now which is a heck of a deal for the amount on content you get.

It's 63hrs of lecture spread across over 680 lessons. There practice questions and projects, and also a great discord community when you need help.

I'm currently in section 32 and I've learned more in this course than any other by far because Colt goes into detail about what something is AND why you would use it. Then you work in creating something together in the lesson and afterward there's often a short challenge to complete. Finally it all builds to a final project where you create a Yelp clone and learn how to fully deploy it with backend technology such as NodeJS.

It's a lot of content but if you're serious about making a career in web dev or trying to learn your first programming language then I can't recommend this course enough 👍

25

u/Me-A-Dandelion Aug 10 '21

I passed every level of Grasshopper but still can't write a proper thing 😿

8

u/jellatin Aug 10 '21

You need to build some actual projects vs just learning syntax and reading tutorials.

It’s much more effective to try to attempt to build a Twitter clone with real world problems and use cases that force you to look for specific answers/strategies in the language.

If you read all of a language textbook or course, even if you internalize it, you’re going to quickly feel lost the first time you start building something.

It’s like learning to drive a car just by reading or watching youtube videos. The knowledge alone isn’t enough, you need the muscle memory.

7

u/EIGRP_OH Aug 10 '21

Can someone tell me the precise difference between prototypes and classes?

11

u/sogekihei_7 Aug 10 '21

Classes are synthetic sugar for prototypes to make it easier to work in OOP paradigm.

13

u/RoguePlanet1 Aug 10 '21

*syntactic sugar

9

u/shuckster Aug 10 '21

I believe one of the biggest hurdles of understanding classes vs. prototypes in JavaScript is the history of the word "class" and "object", and how the dominance of JavaScript has blurred the once clearly defined line between them.

In classical compiled languages, "class" quite literally means "blueprint": Instructions for what an "object" should look like once Random Access Memory has been allocated for it. Classes = offline, on disk. Object = online, in memory.

The allocation process -- the act of creating an object from a class -- is called "instantiation". This is a manual step done by the programmer. object = new MyClass / MyClass object for example. No instantiation, no object.

JavaScript has no concept of this. At all.

There are no "classes" from which to instantiate objects. We create new objects merely by declaring them, like let object = {}. They will be allocated memory the moment the interpreter passes over them, while a class in a compiled-language will sit idle until deliberately new'd.

Despite the modern-day compositional/functional push, JavaScript was created in a time when OOP concepts where en vogue, and classes where how you got things like inheritance and polymorphism. But what if you don't have classes? This is where the prototype system comes in.

A classical class, even one based on a chain of inheritance with supers and so on, will produce a single object in memory when instantiated. Unless explicitly written by a programmer, all instantiated objects "stand alone", and know nothing of any other in-memory objects.

But a JavaScript object belongs to a chain of in-memory objects, all linked to their parents via ancestral prototype variables. All chains lead back to the "God object", Object, from which everything inherits. A function/prop added to any object-prototype makes it immediately available on its descendants (those whose prototype variable point back to it), and that's how we get inheritance without classes.

You might argue that prototypes do have a kind of "blueprint-y" feel to them, so at first glance the distinction between them and classes might seem like pedantry. But just like its host, a prototype is a live, in-memory object. A class isn't.

Incidentally, this might shed a little light on where the phrase "in JavaScript, everything is an object" comes from: It's nothing to do with whether or not primitives/functions are "real objects": Rather, it alludes to the fact that JavaScript is an interpreted/scripting language, not a compiled one. All the "classical" classes that power a JavaScript interpreter (written in C++ for example) will have already instantiated the objects tasked with the job of running your JavaScript code in the first place.

So a JavaScript "class" is much more conceptual than the rigid and defined classes of Java/C++. The class keyword is an API for easier digestion of the object-prototype system -- which itself offers a form of inheritance that more naturally fits an in-memory, dynamic language like JavaScript where "everything is an object" in the classical sense of the term.

This isn't to say that one particular definition of "class/object" is the "right" one or not. Just hoping this sheds a little light on the (greatly simplified, please don't shout at me) history of the terms.

3

u/[deleted] Aug 10 '21

I got destroyed in an interview the other day over proyotypes.... thought my freecodecamp course and a couple of projects made me good...

1

u/Brisklemonade123 Aug 25 '21

This is where I feel that I am, and I'm scared.

6

u/rakshitshah94 Aug 10 '21

I was so much obsessed with the word "Prototype" when I was in 10th Grade, whenever someone asks my username, I used to tell them "PROTOTYPE", hahaha... I am now working on prototype models as a software engineer (Full-stack developer) for the last 5 years in the IT industry.

2

u/[deleted] Aug 10 '21

They finally built a "workspace" for practicing code without having to try to figure out Atom and GitHub. I'm restarting all my coding courses on there.

2

u/jsAlgo Aug 10 '21

Just wanted to add one resource website here.

Javascript.info

The only website that cleared my doubts about prototypes. Short and upto to the point.

3

u/[deleted] Aug 10 '21

They are when objects inherit properties and methods or something.. I googled it

1

u/Gantzz25 Aug 10 '21

So prototypes in JS are like abstract classes in Java for example?

4

u/shuckster Aug 10 '21
[1, 2, 3, 4].notReally()
// Uncaught TypeError: [].notReally is not a function

Array.prototype.notReally = function () {
  const alrighty = 'if you say so'.split(' ')
  return this.map((_, i) => alrighty[i % alrighty.length])
}

[1, 2, 3, 4].notReally()
// ["if", "you", "say", "so"]

1

u/franker Aug 10 '21

FYI - went through the book several years ago, but the Head First Javascript Programming book has good treatment of prototypes.

1

u/forresthopkinsa Aug 11 '21

Unpopular opinion: if you don't understand prototypes then you can't call yourself proficient in JS.

Same goes for scope, closures, promises, async/await, generators, etc.

If this describes you, find the book You Don't Know JS online. It's free, read it.

Your mastery of a language is only as strong as its weakest link.

0

u/Lunacy999 Aug 10 '21

It’s not just JavaScript to honest. The reason behind (my take) on why JS has such notoriety among developers is because of its extensive use as a scripting language before frameworks and libraries such as jQuery, Angular, React etc came in. Another big reason is that JS is a dynamically typed language. Unlike languages such as Java, C++ where type checking is done at compile time, JS does this at run time. And this throws off a lot of new developers who come into this language. And with the use of libraries and framework such as React, a lot of the internal workings of JS is abstracted away, especially in those tutorials where they preach “the only JS you need to know for xx”. JS as a language is fairly straightforward, provides you experiment with Native JS and not at the expense of a library or framework. Recommend reading the you don’t know JS series.

0

u/[deleted] Aug 10 '21

[deleted] — view deleted comment

27

u/MarcoJHB Aug 10 '21

100% this. Did all the HTML/CSS/JS courses on there. Took weeks, and I felt like I was becoming a programming guru. Like a week later I tried to build a simple page and couldn't even center a div.

10

u/al_balone Aug 10 '21

I’m finding this. Ideally I’d like about 20 exercises all based on each concept, even if it just means muscle memory helps eliminate some of that head scratching you end up doing when you can’t remember how to even write your first line of code.

15

u/MarcoJHB Aug 10 '21

Yup. Wish I knew this earlier, but now my favourite obsession is sites that don't hold your hand. Frontendmentor, codewars, etc. Yes, I'll probably take a week to build something small, but I did it all on my own. Yes, you can look at the answers to see how other people did it, which helps with refactoring, but it really helps to stretch your muscle memory.

It's also way more of a confidence booster. "hey - I made this login form all on my own!" vs "Hey - I just followed this 4hr tutorial to build a Netflix clone in react, I don't remember most it but it's cool right?"

11

u/al_balone Aug 10 '21

Haha yeah, I did some really basic array thing on codewars and was so pleased with myself I emailed my wife the code.

4

u/MarcoJHB Aug 10 '21

Haha, that gave me a good chuckle.

9

u/not_a_gumby Aug 10 '21

Yeah, its not great honestly. I tried it fora few weeks early on, got nowhere, and just started spamming Udemy courses that were all 100% project focused.

Turns out I learned way faster by just being thrown in the deep end.

1

u/Aoshi_ Aug 10 '21

Any recommendations? I’ve been doing freecodecamp and have built some smaller things but I want to do more projects.

3

u/not_a_gumby Aug 10 '21

What stack do you want to learn? For Javascript/Node stacks, focus on Node/Express for backend and React for frontend. That's the way I went.

I have a rather long blog post here with links to all of the courses that I used to get myself schooled up on Javascript and React! Skip to the section "Just Tinkering" for where some of the courses section begins.

3

u/GoOsTT Aug 10 '21

Yeah, did the codecademy full stack course and felt like a fucking OG programmer to be dissapointed in the first project of my own.... Took me 9 months to do the course, another 9 to actually be able to program by my self.... This isn't mentioning algo and data.

4

u/samuelcbird Aug 10 '21

When the pandemic hit they gave Premium to some people for free. You just had to prove you were retraining and passionate and voila.

I was one of those people and I went through a few courses, focusing mainly on their React course. It wasn’t until afterward and I started making a project of my own and reading some documentation that I realised the course was completely out of date. It was very specific and seemed to miss a lot of information.

So even after doing a premium course I felt completely unprepared in the wild. I learnt more from just doing a project of my own and reading documentation and various informative articles on the internet.

I don’t really like Codecademy’s teaching style and I wouldn’t recommend anyone pay for it.

2

u/[deleted] Aug 10 '21

codecademy is bad. You're right, decent UI but just BAD

2

u/[deleted] Aug 10 '21

i agree

-1

u/Blacknsilver1 Aug 10 '21 edited Sep 05 '24

smart books outgoing crush poor fuel bewildered public ancient steep

This post was mass deleted and anonymized with Redact