Explain difference between: function Person(){} , var person = Person() , and var person = new Person() ?
Explain difference between: function Person(){} , var person = Person() , and var person = new Person() ?
To answer the interview question regarding the differences between function Person(){}, var person = Person(), and var person = new Person(), it's important to understand the context in which each is used in JavaScript, particularly focusing on function declarations, function calls, and object instantiation.
function Person(){}:
Person. It doesn't execute the function but merely sets up the function structure in memory. The function can be called later in the code. This function, when called, will execute the code block defined within its braces {}. If used with the new keyword, it can act as a constructor to create new objects.var person = Person():
Person and assigns its return value to the variable person. If the Person function does not explicitly return a value, person will be assigned undefined. This usage does not involve object creation directly unless the Person function itself returns an object. This is a simple function call and is not used for creating an instance of an object in the context of object-oriented programming.Can you describe the main difference between a .forEach loop and a .map() loop and why you would pick one versus the other?
Xem chi tiếtCan you give an example for destructuring an object or an array in ES6?
Xem chi tiếtCan you give an example of a curry function and why this syntax offers an advantage?
Xem chi tiếtĐăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.