Check out a free preview of the full Introduction to Data Structures for Interviews course:
The "Stack: Q&A" Lesson is part of the full, Introduction to Data Structures for Interviews course featured in this preview video. Here's what you'd learn in this lesson:

Bianca answers questions from students about the challenges with the implementation of the stack data structure and the usage of private variables.

Get Unlimited Access Now

Transcript from the "Stack: Q&A" Lesson

>> Bianca Gandolfo: When you guys were implementing this on your own, what were some pieces that were confusing?
>> Speaker 2: Just how the data was being stored, basically? So it made sense just to implement with an array.
>> Bianca Gandolfo: Yeah, yeah, yeah, yeah.
>> Speaker 2: And I was like, well, it already works like a stack, [LAUGH].

[00:00:23] So as an object, it was the challenge, the subject.
>> Bianca Gandolfo: Cool,
>> Bianca Gandolfo: Anything else, any questions, comments? Things that you feel like you need to pay attention to when you implement this on your own, that might be confusing later, no?
>> Speaker 3: Maybe a weird side questions, line 6, line 7, right?

[00:00:52] Using the underscore to denote, hey, don't access this outside of methods, internal. I know in Ruby, you can set private methods, protected methods. Is there any JavaScript analog to that, where you can actually physically lock the process, or is it always, yeah?
>> Bianca Gandolfo: It's complicated, I mean, the answer is yes.

[00:01:14] There are a lot of ways you can go about doing it, usually they're a lot of work. So you can use things like closures, and then you can also freeze objects and stuff like that, so you can't actually change them. But in general, it's okay just to do the underscore, and people will understand that that is not to be messed with.

[00:01:40] Yeah, especially if you're using a class constructor in this way, you're not gonna be able to make it private.
>> Bianca Gandolfo: Good question.