Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
51 lines (42 loc) · 1.72 KB

File metadata and controls

51 lines (42 loc) · 1.72 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Learning JavaScript</title>
</head>
<body>
<center><h1>Functions</h1></center>
<h3>If we have a piece of code and we want to run lot of time we can put then into the function and use it instead of using again and again. </h3>
<p><strong>JavaScript Function Syntax</strong></p>
<ol>
<li>A JavaScript function is defined with the function keyword, followed by a name, followed by parentheses ().</li>
<li>Function names can contain letters, digits, underscores, and dollar signs (same rules as variables).</li>
<li>The parentheses may include parameter names separated by commas:
(parameter1, parameter2, ...)</li>
<li>he code to be executed, by the function, is placed inside curly brackets: {}</li>
</ol>
<h2>Example:</h2>
<p>function calculateAge(birthYear){<br />
return 2018 - birthYear;<br />
}<br />
<br />
var ageRoopak = calculateAge(1992);<br />
var ageBrooke = calculateAge(1993);<br />
var ageRamesh = calculateAge(1991);<br />
console.log(ageRoopak, ageBrooke, ageRamesh);<br />
function yearUntilRetirement(year, firstName) {<br />
var age = calculateAge(year);<br />
var retirment = 65 - age;<br />
console.log(firstName + ' retires in ' + retirment + 'years.');<br />
}<br />
<br />
yearUntilRetirement(1992, 'Roopak');<br />
yearUntilRetirement(1993, 'Brooke');<br />
yearUntilRetirement(1991, 'Ramesh');</p><br />
<form action="func_result.html">
<input type="submit" name="Check" value="Check">
<p>click 'Check' to see the answer</p>
</form>
</body>
<script src="functions.js"></script>
</html>
Morty Proxy This is a proxified and sanitized view of the page, visit original site.