Home > Client Side Scripting > Function di Javascript

Function di Javascript

September 26, 2014 Leave a comment Go to comments

Function di javascript dapat dibuat dengan 2 cara yaitu declaration dan expression.

1. Declaration

function functionName ( parameters_1, parameters_2, parameters_n) {

/*logic goes here */

}

2. Expression

var variableName = function (parameters_1, parameters_2, parameters_n ) {
/*logic goes here */
}

setelah function expression di-assing ke variable, variable dapat digunakan sebagai function.
variableName(parameters_1, parameters_2, parameters_n );

Return pada function adalah optional, selama code dalam function benar maka JS engine tidak akan menghasilkan error. Jika void function secara implisit akan me-return undefined, jadi statement return undefined;equal dengan statement return; dan equal dengan tanpa statement return.

Semoga bermanfaat.🙂

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: