UrbanPro
true

Learn Website Scripting from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Javascript function

Masroor Ahmad
19/01/2017 0 0
Q1.function f() {
   ...
}


var f = function() {
    ...
};

Which will work?

Both will work. The difference here is that one is a named function ( function f() ) while the other is a variable equal to a function ( var f = function() ). You have to be careful when setting variables equal to functions. This will work: var f = function(n) { console.log(n); }; f(3); // logs 3 But this will break, since the variable is defined after the call to it. f(3); // what is f? breaks. var f = function(n) { console.log(n); }; But normal functions work fine. function abc(n) { console.log(n); } abc(3); // logs 3 xyz(5); // logs 5 function xyz(n) { console.log(n); } This is because the code is analysed before execution, and all functions are available to call. But setting a var equal to a function is like setting a var to anything else. The order of when it happens is important.
0 Dislike
Follow 0

Please Enter a comment

Submit

Other Lessons for You

Why AngularJS Got Popular
AngularJS became very popular due to its easy two-way data binding, MVC architecture, built-in module system, dependency injection, and routing package. Initially built as a hobby project by Misko Hevery...

What is JavaScript MV* Frameworks?
MV* (as in, model-view-wildcard) design patterns. There's MVC (model-view-controller), MVVM (model-view-view model), MVP (model-view-presenter), and probably some more. Some of popular JavaScript MV*...
S

Subrahmanyam P.

0 0
0

AngularJS Routes
Q. How to set up Angular JS Routes? Ans: Set up the application in below format: AngularJS(Folder)/ ---index.html ---home.html ---about.html ---css/style.css ---js/angular.js ---js/angular--routes.js ---js/app.js i....

.NET With AngularJS Training Program Syllabus
What You will Learn in .NET with AngularJS Training Program? Introduction to .Net: Features of .Net, CTS, CLS, CLR and MSIL. C# & .Net Basics and Branching & Flow Control. OOPs Concepts,...

Angular 1 vs Angular 2
Angular team has released the angular 2, which has drastically change the way programmers interact and work with Angular framework in the past. In this post I will tell you the common changes made by...

Looking for Website Scripting Training?

Learn from Best Tutors on UrbanPro.

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Website Scripting Classes?

The best tutors for Website Scripting Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Website Scripting with the Best Tutors

The best Tutors for Website Scripting Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more