MainMenu

Home Java Overview Maven Tutorials

Saturday, 14 January 2017

Function is Javascript with example

Function is just way to reuse the code which can be called anywhere in the program.
Definition : A javascript function is a block of code designed to perform a perticular task.
Note : To define a javascript function, use the function keyword followed by name & set of paraemeter.
Syntax of function :
<script type = "text/javascript">
function function_name(function parameter)
{
function body
}
</script>
Example : In this example we will call the function from a button
<html>
<head>
<title> Welcome to learing nation</title> <script type = "text/javascript"> function chandan()
{
alert("i have been called");
}
</script>
</head>
<body>
<input type = "button" value = "Submit" onclick = "chandan()">
</body>
</html>
Output : i have been called.
Function Return : Use the return statement to return a value
Example : In this example first function will return the value to the second function :
<html>
<head>
<title> Welcome to learing nation</title>
<script type = "text/javascript">
function chandan(a,b)
{
var c = a * b;
return c;
}
function csc()
{
var x = prompt("Enter your first number");
var y = prompt("Enter your second number");
var z = chandan(x, y);
document.write("your answer is :" +z);
}
</script>
</head>
<body>
<input type = "button" value = "Submit" onclick = "csc()">
</body>
</html>

8 comments:

  1. تعد شركة ركن الامانة (0505561372) من الشركات المتخصصة فى اعمال التنظيف و النقل و المكافحة بالمنطقة الجنوبية فى المملكة العربية السعودية فهى تقدم خدمات متميزة وعلى اعلى مستوى من الخبرة و التقنية بالاعتماد على عمال مدربين ومتميزين فى عمالهم ونقدم خدمات باقل الاسعار التى تناسب جميع عملائنا الكرام فتواصلوا معنا على رقم الشركة
    شركة تنظيف بخميس مشيط
    شركة تنظيف منازل بخميس مشيط
    شركة تنظيف كنب بخميس مشيط
    شركة تنظيف خزانات بخميس مشيط
    شركة عزل اسطح بخميس مشيط
    شركة عزل خزانات بخميس مشيط
    شركة كشف تسربات المياه بخميس مشيط
    شركة تسليك مجارى بخميس مشيط
    شركة مكافحة حشرات بخميس مشيط
    شركة نقل اثاث بخميس مشيط

    ReplyDelete
  2. leather jackets can really make you look good, they also make you feel warm and comfortable” web design agencies los angeles

    ReplyDelete
  3. He keeps both strands moving along at equal pace, Cage’s is more engrossing; the film paying sly hint to knowing so when it utilises the concoction of Hit-Girl to drive the film’s final act on behalf of Cage’s plight. web design la

    ReplyDelete
  4. I am really loving the theme/design of your web site. Do you ever run into any browser compatibility problems? A few of my blog readers have complained about my website not working correctly in Explorer but looks great in Chrome. Do you have any tips to help fix this issue? web design

    ReplyDelete
  5. I have understand your stuff previous to and you’re just too great. I really like what you’ve acquired here, really like what you’re stating and the way in which you say it. You make it entertaining and you still care for to keep it sensible. I cant wait to read much more from you. This is actually a great website.from https://onlinetechnicalguide.com/

    ReplyDelete
  6. I really appreciate the kind of topics you post here. Thanks for sharing us a great information that is actually helpful. Good day!
    Animation Studio From India

    ReplyDelete