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

rn4 js4

The document discusses different types of JavaScript functions: functions without arguments, functions with arguments, functions with return values, and JavaScript function objects. It defines each type of function and provides an example of how to write one. The document also demonstrates calling the functions and returning/displaying values from functions.

Uploaded by

newsneha775
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

rn4 js4

The document discusses different types of JavaScript functions: functions without arguments, functions with arguments, functions with return values, and JavaScript function objects. It defines each type of function and provides an example of how to write one. The document also demonstrates calling the functions and returning/displaying values from functions.

Uploaded by

newsneha775
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

<!

DOCTYPE html>

<html>

<head>

<title>Experiment 4</title>

<style>

body

font-family: Ariel;

margin: 300px;

</style>

</head>

<body>

<div style="background-color:blue; color:white;border-radius:5px;

padding:20px">Javascript Function</div><br><br>

<div onclick="noarg()" style="background-color:lightgrey; cursor:pointer; padding:

3px; height:25px;"><b>Function without Argument</b></div><br><br>

<div onclick="arg('Argument')" style="background-color:lightgrey; cursor: pointer;

padding: 3px; height: 25px;">

<b>Function with Arguments</b>

</div><br><br>

<div onclick="displayReturnValue()"

style="background-color:lightgrey; cursor: pointer; padding: 3px; height:

25px;"><b>Function with a Return

Value</b></div><br><br>

<div onclick="functionObject()" style="background-color:lightgrey; cursor:pointer;

padding: 3px; height: 25px;border-radius:5px;">

<b>JavaScript Function Object</b>

</div><br><br>
<script>

function noarg()

document.write("<strong><u>Function without Argument</u></strong><br><br>Afunction without


arguments in JavaScript is a named unit of code that is created usingthe<strong>function</strong>
keyword, followed by the function's name, an empty pair ofparentheses <strong>()</strong>, and a
pair of curly braces <strong>{}</strong> containing the code to beexecuted. When this type of
function is called, it runs its internal codewithout expecting any values to be passed to it.");

function arg(var1)

document.write("<strong><u>Function with " + var1 + "</u></strong><br><br>A function with


arguments in JavaScript is a named block of code that is created using the <strong>function</strong>
keyword, followed by the function's name, a set of parentheses <strong>()</strong>, and a list of
parameter names separated by commas and and a pair of curly braces <strong>{}</strong>
containing the code to be executed. When this type of function is called, values can be passed as
arguments into the function's parameters, allowing it to work with and manipulate the provided
data.");

function displayReturnValue()

var result = returnval("Return"); document.write(result);

function returnval(var2)

var message = "<strong><u>Function with " + var2 + "Value</u ></strong > <br><br>A function with
a return value in JavaScript is a named block of code that is created using the
<strong>function</strong> keyword, followed by the function's name, a set of parentheses
<strong>()</strong>, optional parameters, and a block of code within curly braces <strong>{
}</strong>. Inside the function, the return statement is used to specify the value that the function
should produce as its output.";

return message;

function functionObject()

var obj = "<strong><u>Javascript Function Object</u></strong><br><br>A


JavaScript function object is a special type of object that holds executable code, making it reusable
and allowing it to be assigned to variables, passed as arguments, returned from functions, and
manipulated like other data values. It combines the behavior of a function <strong>(code
execution)</strong> with the properties and capabilities of an object <strong>(storing data and
having methods)</strong>.";

var output = new Function("obj", "return obj;");

document.write(output(obj));

</script>

</body>

</html>

You might also like