Home
Aptitude
Categories


Home » JavaScript

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.

Example:

    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

Code:

<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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.