當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JavaScript | 演示函数中按值调用的示例
生活随笔
收集整理的這篇文章主要介紹了
JavaScript | 演示函数中按值调用的示例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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.
在這里,我們正在設計一個名為change()的函數,該函數具有一個參數,并且試圖更改該函數內部傳遞的參數的值,但不會影響在調用時作為參數傳遞的main / actual參數。
Example:
例:
a =10Value before function call: a = 10//calling functionchange(a)//changing inside the function a = 67Value inside the function: a = 67//printing the value after the function callValue after the function call: a =10Code:
碼:
<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翻譯自: https://www.includehelp.com/code-snippets/call-by-value-in-function-javascript.aspx
總結
以上是生活随笔為你收集整理的JavaScript | 演示函数中按值调用的示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java PipedInputStrea
- 下一篇: html导航栏点击不能跳转,无法单击导航