当前位置:网站首页>5. Reference type and value type as function parameters?
5. Reference type and value type as function parameters?
2022-07-24 18:21:00 【yingxingyf】
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input type="button" value=" test " onclick ="testf()" />
</body>
</html>
<script type="text/javascript">
/*
function testf(){
var m = 20;
var n = 30;
var t = max(m,n);
console.log(t);
}
//1、 Value type as parameter of function : Value passed .
function max(x,y){
var m;
if(x>y){
m = x;
}else{
m = y;
}
return m;
}
*/
function testf(){
var ages = [28,10,19,25,21,38,8];
bubble(ages);
for(var i in ages){
document.write(ages[i]+",");
}
}
//2、 Reference types as arguments to functions , It's address delivery ( The address saved in the argument was passed to the formal parameter , That is, the arguments and formal parameters point to the same memory area )
// Bubble sort
// Parameters : Array ( A disorderly )
// Return value : Array ( In order )
function bubble(arr){
for(var i=0;i<arr.length-1;i++){
for(var j=0;j<arr.length-1-i;j++){
if(arr[j]>arr[j+1]){
var temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] =temp;
}
}
}
return arr;
}
function bubble2(arr){
var arrnew = [];// A new address has been opened in the pile
for(var i=0;i<arr.length-1;i++){
for(var j=0;j<arr.length-1-i;j++){
if(arr[j]>arr[j+1]){
var temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] =temp;
}
}
}
return arr;
}
</script>
1. Schematic diagram of value type as function parameter :
2. quote ( object ) Type as function parameter diagram :
边栏推荐
- ORM introduction and database operation
- Pytoch's journey 1: linear model
- Typora is still the most beautiful and beautiful document editing artifact of yyds in my heart. I believe you will never abandon it
- 0615 ~ realize RBAC permission management with user-defined annotations
- Template syntax [easy to understand]
- 缺失值处理
- Go to bed capacity exchange
- Variable and immutable data types
- How to prepare for hyperinflation
- 去不图床容量兑换
猜你喜欢

The drop-down list component uses iscrol JS to achieve the rolling effect of the pit encountered

Typora is still the most beautiful and beautiful document editing artifact of yyds in my heart. I believe you will never abandon it

["code" power is fully open, and "chapter" shows strength] list of contributors to the task challenge in the first quarter of 2022

Mid year inventory | in 2022, PAAS will be upgraded again

【刷题记录】20. 有效的括号

Sword finger offer 21. adjust the array order so that odd numbers precede even numbers

0630~ professional quality course

下拉列表组件使用 iScroll.js 实现滚动效果遇到的坑

【obs】依赖库: x264 vs 构建

Three ways of redis cluster
随机推荐
Typora 它依然是我心中的YYDS 最优美也是颜值最高的文档编辑神器 相信你永远不会抛弃它
Mozilla foundation released 2022 Internet health report: AI will contribute 15.7 trillion yuan to the global economy in 2030, and the investment in AI in the United States last year was nearly three t
数组对象方法 常用遍历方法&高阶函数
New can also create objects. Why do you need factory mode?
0615 ~ realize RBAC permission management with user-defined annotations
JS array method sort() collation parsing
关于接口的写法 1链式判读 ?. 2方法执行 (finally)一定会执行
0701~ holiday summary
可撤销并查集板子
The 5th Digital China Construction summit opened in Fuzhou, Fujian
Space three point circle code
Still building projects from scratch? This upgraded rapid development scaffold is worth a try!
Get the original data API on 1688app
Several sorting methods for while and sort
Template syntax [easy to understand]
Show or hide password plaintext + password box verification information
Icml2022 Best Paper Award: learning protein reverse folding from millions of predicted structures
Goodbye Navicat! This open source database management tool has a cooler interface!
middleware
如何向 google colab 快速上传文件