×

Index

JavaScript Tutorial

JavaScript Examples

CSS Tutorial

CSS Examples

JavaScript | Demonstrate the example of call by value in function

Here, we are going to learn about the change by value in the JavaScript function with the example.
Submitted by Pankaj Singh, on October 10, 2018

Example of call by value in function

Here, we are designing a function named change() that has an argument and we are trying to change the value of the passed argument inside the function, but it will not effect to the main/actual argument that is passed as the argument while calling.

Sample Input/Output

a =10
Value before function call: a = 10
//calling function
change(a)
//changing inside the function 
a = 67
Value inside the function: a = 67
//printing the value after the function call
Value after the function call: a =10

JavaScript code to demonstrate the example of call by value in function

<html lang="en">
<head>
    <script>
        function change(a){
            a=67;
            document.write("Inside Function: A = "+a+"<Br />");
        }
    </script>
</head>
<body>
    <script>
        var a=10;
        document.write("Before Calling : A = "+a+"<br />");
        change(a);
        document.write("After Calling : A = "+a+"<br />");
    </script>
</body>
</html>

Output

Before Calling : A = 10
Inside Function: A = 67
After Calling : A = 10

JavaScript Examples »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.