How do you add an element at the beginning of an array?
You can use array.unshift() to insert elements at the begining of an array.
How do you add an element at the end of an array?
You can use array.push() to insert elements at the end of an array.
Why extending array is bad idea?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:
- for..in might not work properly.
- Someone else might also want to extend Array with the same function name.
- It might not work properly in every browser.
How do you check if an object is an array or not?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.
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.
How can you get the type of arguments passed to a function?
You can use the typeOf function to get the type of arguments passed to a function.
Difference between private, public and static variable?
- 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.
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").
The blur() method is used to remove focus from an element.
What is NaN?
NaN is just a special value to return as a result of conversion to number instead of throwing an exception, if type conversion has failed.
What is the difference between ViewState and SessionState?
ViewState is specific to a page in a session.
SessionState is specific to user specific data that can be accessed across all pages in the web application.
Just add "use strict"; at the top of your code, before anything else.
Moreover, that depends on what kind of calculations you're doing.
- If you really need your results to add up exactly, especially when you work with money: use a special decimal datatype.
- If you just don't want to see all those extra decimal places: simply format your result rounded to a fixed number of decimal places when displaying it.
- If you have no decimal datatype available, an alternative is to work with integers, e.g. do money calculations entirely in cents. But this is more work and has some drawbacks.
Your computer most likely locked up because the infinite loop made the browser you were using unstable.
The unshift() method adds new items to the beginning of an array and returns the new length of the array.
- What is noscript tag?
- Difference between '=', '==' and '===' operators?
- What is Browser Object Model
- How to test a string as a literal and as an object ?
- What is Associative Array? How do we use it?
- What's the Difference Between Class and Prototypal Inheritance?
- Event bubbling and Event Capturing in JavScript?
- What is the difference between .call() and .apply()?
- What is an immediately-invoked function expression?
- What Are RESTful (REpresentational State Transfer)Web Services?
- TypeError: document.getelementbyid(...) is null
- What's the difference between Null and Undefined?