0% found this document useful (0 votes)
5 views

Function Javascript - pptx-1

The document discusses functions in JavaScript including how to build functions, use parameters in functions, and define return values for functions. It provides examples of each and explains that functions allow storing reusable code to perform single tasks instead of rewriting code. Parameters allow passing values to functions and default values can be set. Return values specify what a function returns after completing.

Uploaded by

Zulham Ariyandi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Function Javascript - pptx-1

The document discusses functions in JavaScript including how to build functions, use parameters in functions, and define return values for functions. It provides examples of each and explains that functions allow storing reusable code to perform single tasks instead of rewriting code. Parameters allow passing values to functions and default values can be set. Return values specify what a function returns after completing.

Uploaded by

Zulham Ariyandi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Function

JavaScript
Build, Parameter and Return
Table of Content

● Build Function ● Return Function


● Parameter Function
Build Function

Functions are an important part of programming languages. Without realizing it, we actually used a
function in the previous code sample.

For Example…

alert('This is a message' );
Build Function

Another essential concept in coding is functions, which allow you to store a piece of code that does
a single task inside a defined block, and then call that code whenever you need it using a single
short command — rather than having to type out the same code multiple times.

Code…

function displayMyScore() {
// Code……
}
Build Function

Let's Code…
Parameter Function

Some functions require parameters to be specified when you are invoking them

const myText = 'I am a string';


const newString = myText.replace('string', 'sausage');

If you're writing a function and want to support optional parameters, you can specify default values
by adding = after the name of the parameter, followed by the default value:

function hello(name = 'Chris') {


console.log(`Hello ${name}!`);
}

hello('Ari'); // Hello Ari!


hello(); // Hello Chris!
Parameter Function

Let's Code…
Return Function

Some functions don't return a significant value, but others do.

Return values are just what they sound like — the values that a function returns when it completes.

Example
Cheers
🍻

You might also like