Page 106 - DCAP202_Fundamentals of Web Programming
P. 106
Unit 8: Programming Constructs in JavaScript
Self Assessment Notes
Fill in the blanks:
4. The ........................... loop is used when you know in advance how many times the script
should run.
5. The ........................... loop loops through a block of code while a specified condition is true.
6. The ........................... loop will execute the block of code ONCE, and then it will repeat the
loop as long as the specified condition is true.
7. The ........................... statement will break the loop and continue executing the code that
follows after the loop (if any).
8. The ........................... statement will break the current loop and continue with the next
value.
8.3 Functions
To keep the browser from executing a script when the page loads, you can put your script into a
function.
A function contains code that will be executed by an event or by a call to the function.
You may call a function from anywhere within a page (or even from other pages if the function
is embedded in an external .js file).
Notes Functions can be defined both in the <head> and in the <body> section of a document.
However, to assure that a function is read/loaded by the browser before it is called, it
could be wise to put functions in the <head> section.
8.3.1 Function Literals
JavaScript 1.2 introduces the concept of function literals which is one more new way of defining
functions.
A function literal is an expression that defines an unnamed function.
Syntax
The syntax for a function literal is much like that of the function statement, except that it is used as
an expression rather than as a statement and no function name is required.
<script type=”text/javascript”>
<!—
var variablename = function(Argument List){
Function Body
};
//—>
</script>
LOVELY PROFESSIONAL UNIVERSITY 99