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

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.


    a =10
    Value before function call: a = 10
    //calling function
    //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


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


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

JavaScript Examples »

Comments and Discussions!

Copyright © 2023 All rights reserved.