Skip to main content

Posts

Showing posts with the label difference between call and apply javascript

What is the difference between the function declarations below?

What is the difference between the function declarations below? var user = function () { //TODO: Some code }; And function country() { //TODO: Some code }; Answers :- The main difference is the function user is defined at run-time whereas function country is defined at parse time. For example as, < script type = "text/javascript" > //WHEN WE CALLING USER FUNCTION HERE WILL THROW AN ERROR. user(); var user = function (){ alert( "Hello, I am a user!" ); }; < /script> < script type = "text/javascript" > //WHEN WE CALLING USER FUNCTION HERE WILL NOT THROW AN ERROR. country(); function country(){ alert( "Hello, I am a country!" ); }; < /script> Stayed Informed – Best JavaScript Interview Questions & Answers I hope you are enjoying with this post! Please share with you friends. Thank you!!

difference between call and apply in JavaScript

What is the difference between call and apply? CALL  -   Call a function with the specified arguments. You can use call, if you know how many argument are going to pass to the functions. APPLY -   Call a function with argument provided as an array. You can use apply if you don't know how many argument are going to pass to the functions. Both (call and apply) are using to call a functions. Here is an advantage over apply and call. The . call() method is little bit faster than . apply() method. Go to live demo example http://embed.plnkr.co/4Rb8Ur/preview Example code as given below. < !DOCTYPE html > < html > < head >     < meta charset ="utf-8" />     < title > The Difference Between Call and Apply in JavaScript </ title >     < link rel ="stylesheet" href ="style.css" />     < script >    ...

39 Best Object Oriented JavaScript Interview Questions and Answers

Most Popular 37 Key Questions for JavaScript Interviews. What is Object in JavaScript? What is the Prototype object in JavaScript and how it is used? What is "this"? What is its value? Explain why "self" is needed instead of "this". What is a Closure and why are they so useful to us? Explain how to write class methods vs. instance methods. Can you explain the difference between == and ===? Can you explain the difference between call and apply? Explain why Asynchronous code is important in JavaScript? Can you please tell me a story about JavaScript performance problems? Tell me your JavaScript Naming Convention? How do you define a class and its constructor? What is Hoisted in JavaScript? What is function overloadin...