Net-informations.com
SiteMap  | About    

JavaScript Interview Questions FAQ - 2

You can use array.unshift() to insert elements at the begining of an array.

You can use array.push() to insert elements at the end of an array.

The problem is the global scope. Changing the behaviour of an object that will only be used by your own code is fine. But when you change the behaviour of something that is also used by other code there is a risk you will break that other code.

Possible porblems:

  1. for..in might not work properly.
  2. Someone else might also want to extend Array with the same function name.
  3. It might not work properly in every browser.

Object.prototype.toString returns the value of the object's internal [[Class]] property. Every object has a toString() method that is automatically called when the object is to be represented as a text value or when an object is referred to in a manner in which a string is expected. By default, the toString()method is inherited by every object descended from Object. If this method is not overridden in a custom object,toString() returns '[object type]', where type is the object type.

This code will set the array list to a new empty array. This is perfect if you don't have any references to the original array list anywhere else because this actually creates a brand new (empty) array.

If you need to keep the original array because you have other references to it that should be updated too, you can clear it without creating a new array by setting its length to zero.

Yes. You can assign JavaScript function to variables, which means you can assign anonymous JavaScript functions to variables.

You can use the typeOf function to get the type of arguments passed to a function.

The JavaScript delete operator removes a property from an object; if no more references to the same property are held, it is eventually released automatically. This operator can also delete variables which are not declared with the var statement.

Public variables can be accessed by all the members of the owner as well as other objects that can access the owner

Private variables can be accessed by all the members (functions and variables) of the owner object but not by any other object.

Static variables are come into existence as soon as a class come into existence. It doesn't matter whether the class has any objects or not, static variables would be there.

JavaScript uses an inheritance model called "differential inheritance". It is a common inheritance model used by prototype-based programming languages. What that means is that methods aren't copied from parent to child. Instead, children have an "invisible link" back to their parent object.

The entries() method returns an Array Iterator object with key/value pairs, in the same order as that provided by a for...in loop.

We're checking if a and b are strictly equal (meaning, "referring to exactly the same thing").









net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.