What is the use of functions? Write the general syntax of a JavaScript function.

What will be an ideal response?


When you want to reuse the same JavaScript commands throughout your Web page, you store the commands in a function. A function is a collection of commands that performs an action or returns a value. Every function includes a function name, which identifies it, and a set of commands that are run when the function is called. Some functions also require parameters, which are variables associated with the function.

The general syntax of a JavaScript function is

function function_name(parameters){
JavaScript commands
}

where function_name is the name of the function, parameters is a comma-separated list of variables used in the function, and JavaScript commands are the statements run by the function. Function names, like variable names, are case sensitive. A function name must begin with a letter or underscore (_) and cannot contain any spaces.

Computer Science & Information Technology

You might also like to view...

In a 32-bit bitmap graphic, eight bits are used to define ____.

A. special effects B. color depth C. density D. grayscale

Computer Science & Information Technology

In a form, the text that is included in all letters is also called the ________ text

Fill in the blank(s) with correct word

Computer Science & Information Technology

A(n) _______________ refers to the component that provides the ?touch? part of a touch screen.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

Consider the following code: ? Group Fitness Class Schedule Class Days Times Instructor Room Identify the number of rows in the table.

A. ?2 B. ?5 C. ?1 D. ?Undefined

Computer Science & Information Technology