This question already has answers here:
Is the underscore prefix for property and method names merely a convention?
(6 answers)
Closed 8 years ago.
What is the difference between
prototype.somefunction()
and
prototype._anotherfunction()
I know this might be trivial, but I couldn't find it.
One has an underscore in the name. There's no difference as far as the javascript engine itself is concerned.
However, it's a common convention to name "private" methods such that they start with an underscore.
_ prefix means that method is supposed to be private, not more than that
Related
This question already has answers here:
Get all instances of class in Javascript
(6 answers)
Can I get all instances for a prototype in javascript?
(2 answers)
Closed 1 year ago.
This is not a browser or DOM specific question. If a number of child objects are instantiated from a JavaScript class, is there an easy way to iterate through those objects? I know there might be some way to do this through the Object prototype chain, but I am not sure how to do this or how to do it efficiently. Would this be different in Node versus a browser window?
This question already has answers here:
How is almost everything in Javascript an object?
(6 answers)
Why does a primitive variable act like an Object? [duplicate]
(3 answers)
javascript: do primitive strings have methods?
(2 answers)
Closed 2 years ago.
I have this question in mind since I started learning JavaScript last month.
What I have tried?: I researched for it online almost on all good sites but didn't get satisfactory answer in laymans language.
Question: When I create variable let suppose
let name = "mit"
name.toUpperCase()
I am using dot notation to access the method here and I know we use it for something in object. I was confused if the browser creates different object for name variable (which is of string data type here) or what?
This question already has answers here:
What is the motivation for bringing Symbols to ES6?
(7 answers)
Why do you access Symbol.iterator via brackets?
(3 answers)
Closed 3 years ago.
I recently learned that to get an iterator from an Array, you have to access it using syntax that I have never seen before: let iterator = myArray[Symbol.iterator]()
It seems to me that implementing Array.prototype.getIterator() would have been a more idiomatic way to go, but I must be oversimplifying or just not understanding the significance of accessing this property of arrays in this particular way.
In attempting to deepen my understanding of the inner workings of JavaScript I was hoping someone could explain this diversion from a more traditional syntax.
This question already has answers here:
What does the at symbol (#) do in ES6 javascript? (ECMAScript 2015)
(3 answers)
Closed 6 years ago.
Have viewed
#propertyOrIdentifier // ? What does this mean and do?
used within apparent plain objects or class assignment at Questions and Answers at stackoverflow.
What is the # symbol or character in javascript? What are valid uses?
It is called a decorator.
https://github.com/wycats/javascript-decorators
Medium - Exploring es7 decorators
It doesn't have any special meaning in vanilla JS.
It's likely that wherever you are seeing it it is simply being used as a naming convention, similar to doing something like adding a preceding underscore for private variables _example
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
javascript test for existence of nested object key
In JavaScript, is there an easier way to check if a property of a property exists?
I've been searching for an elegant way to verify if the entire object path is defined.
For example: person.positions.values[0].company.name
On every step of the way, after the person, it can be undefined.
Can this be done without actually going through them one by one?
Thank you.