Quick links
Latest articles
Internship
Members
New...
Algorithms
Discrete Mathematics
Big data
Languages
C
C++
C++ STL
Java
Data Structure
C#.Net
Android
Kotlin
SQL
Web
PHP
Python
JavaScript
CSS
Ajax
Node.js
Web prog.
Programs
C
C++
DS
Java
C#
Python
Aptitude
C
C++
Java
DBMS
Interview
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

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





Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Featured post:
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distribution Software (Distros) of 2018

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions



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 (2015-2018), Some rights reserved.