Preview

Java Script

Powerful Essays
Open Document
Open Document
1085 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Java Script
Java Script
Author By Teacher(Vijaya) Chapter-7

Function Expressions

There are two ways to define a function: by
1.function declaration
2. function expression.

Function Declaration:

function functionName(arg0, arg1, arg2) {
//function body
}

> name property on functions exposing the assigned name.

Ex: alert(functionName.name); //”functionName”

> key characteristics of function declarations is function declaration hoisting, whereby function declarations are read before the code executes.

Ex:

sayHi(); function sayHi(){ alert(“Hi!”); }

This example doesn’t throw an error because the function declaration is read fi rst before the code begins to execute.

Function Expression:

var functionName = function(arg0, arg1, arg2){
//function body
};

The created function is considered to be an anonymous function, because it has no identifier after the function keyword. (Anonymous functions are also sometimes called lambda functions.) This means the name property is the empty string.

Ex: sayHi(); //error – function doesn’t exist yet var sayHi = function(){ alert(“Hi!”); };

Function Declaration | Function Expression | //never do this! if(condition){ function sayHi(){ alert(“Hi!”); } } else { function sayHi(){ alert(“Yo!”); } } | //this is okay var sayHi; if(condition){ sayHi = function(){ alert(“Hi!”); }; } else { sayHi = function(){ alert(“Yo!”); }; } |

Recursion: A recursive function typically is formed when a function calls itself by name .

Ex: function factorial(num){ if (num <= 1){ return 1;
} else { return num * factorial(num-1);
}
}

Although this works initially, it’s possible to prevent it from functioning by running the following code immediately after it:

var anotherFactorial = factorial; factorial = null; alert(anotherFactorial(4)); //error!

because it will try to execute factorial(),

You May Also Find These Documents Helpful

  • Satisfactory Essays

    LAb1Ecet230

    • 221 Words
    • 3 Pages

    2. In the compilation process, what is the difference between an error and a warning?…

    • 221 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Homework Unit 3

    • 354 Words
    • 2 Pages

    1. Statements are execute in order according to the program code. Complex programs can need the help of a decision structure. Statements have to be true to be executed.…

    • 354 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    You can’t use any names that are the same as the functions, statements, and methods.…

    • 218 Words
    • 1 Page
    Satisfactory Essays
  • Satisfactory Essays

    unit 3

    • 313 Words
    • 2 Pages

    4. Assume the variables result, w, x, y , and z are integers, and that w=5, x=4, y=8, and z=2. What value will be stored in result in each of the following statements?…

    • 313 Words
    • 2 Pages
    Satisfactory Essays
  • Better Essays

    7) Global variables make debugging difficult because any statement in a program can change its value.…

    • 1580 Words
    • 11 Pages
    Better Essays
  • Satisfactory Essays

    Javascript Error Handling

    • 255 Words
    • 2 Pages

    2. Write a custom error handling JavaScript function called processErrors that handles a custom error by assigning it to the onerror event handler. Include the block of JavaScript statements needed to pass the arguments sent by the JavaScript interpreter into the processErrors function, send an alert message with the agreements, return, and write the event handler that calls the processErrors function.…

    • 255 Words
    • 2 Pages
    Satisfactory Essays
  • Better Essays

    iv. Names for Java classes follow the same rules as for variable names. It is convention that each word in the class name begins with an upper case letter.…

    • 939 Words
    • 4 Pages
    Better Essays
  • Good Essays

    Java

    • 5076 Words
    • 21 Pages

    Explanation: B) Programs are classified as software to differentiate them from the mechanisms of the computer (hardware). Storage and the processor are two forms of hardware while input is the information that the program processes.…

    • 5076 Words
    • 21 Pages
    Good Essays
  • Satisfactory Essays

    Web Browser

    • 463 Words
    • 2 Pages

    Browser detection – detect which version of browser user is using to adjust viewing settings…

    • 463 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    script

    • 326 Words
    • 1 Page

    1 Given the state of the automotive industry in late 2008/early 2009, is this a great time or a terrible time to launch an innovative car company?…

    • 326 Words
    • 1 Page
    Satisfactory Essays
  • Good Essays

    Java

    • 490 Words
    • 3 Pages

    Write a Java program to demonstrate using bitmaps and bitwise operators to sort and remove duplicates from a file of random phone numbers. Do not confuse the term bitmap used for compressing data into smaller spaces with the bitmap that has come to mean a graphic image.…

    • 490 Words
    • 3 Pages
    Good Essays
  • Good Essays

    and try to make others have this same behavior. In closing this project showed me just how simple it…

    • 731 Words
    • 3 Pages
    Good Essays
  • Good Essays

    Script

    • 1070 Words
    • 5 Pages

    The Embarcadero, one of the most anticipated developments in the city of Legazpi, “soft” opened last July 18, 2009 with two locators opening its doors to the public. The Embarcadero is a major waterfront development located at the harbor area of Legazpi City adjacent to the alluring Kapuntukan Hill.…

    • 1070 Words
    • 5 Pages
    Good Essays
  • Powerful Essays

    Web Browser

    • 2581 Words
    • 11 Pages

    |HTML |- |HTML is a type of computer language that is primarily used for files that are posted on |…

    • 2581 Words
    • 11 Pages
    Powerful Essays
  • Good Essays

    WEB BROWSER

    • 788 Words
    • 4 Pages

    Lack of parental controls, children can just use hidden (ignotio) tabs to hide things from parents (doesn’t show up in history)…

    • 788 Words
    • 4 Pages
    Good Essays

Related Topics