當(dāng)前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JavaScript | 演示函数中按值调用的示例
生活随笔
收集整理的這篇文章主要介紹了
JavaScript | 演示函数中按值调用的示例
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
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.
在這里,我們正在設(shè)計一個名為change()的函數(shù),該函數(shù)具有一個參數(shù),并且試圖更改該函數(shù)內(nèi)部傳遞的參數(shù)的值,但不會影響在調(diào)用時作為參數(shù)傳遞的main / actual參數(shù)。
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
總結(jié)
以上是生活随笔為你收集整理的JavaScript | 演示函数中按值调用的示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java PipedInputStrea
- 下一篇: 使用JavaScript中的示例的esc