当前位置:网站首页>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 :
边栏推荐
- Maximum sum and promotion of continuous subarrays (2)
- A practical scheme of realizing 0.5px on mobile terminal
- 【“码”力全开,“章”显实力】2022年第1季Task挑战赛贡献者榜单
- Pytoch's journey 1: linear model
- Use of jumpserver
- Four ways of simple interest mode
- 0612~quartz timer frame
- 0621~ES&Lucene
- Single cell code analysis - gynecological cancer single cell transcriptome and chromatin accessibility analysis 1
- 0627~ holiday knowledge summary
猜你喜欢

In depth analysis of the famous Alibaba cloud log4j vulnerability

Inheritance and Derive

Typora 它依然是我心中的YYDS 最优美也是颜值最高的文档编辑神器 相信你永远不会抛弃它

怎么解决idea中yaml无法识别或者飘红?

Three ways of redis cluster

redis集群的三种方式

web渗透经验汇总ing

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

Icml2022 Best Paper Award: learning protein reverse folding from millions of predicted structures

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
随机推荐
JS数组方法 sort() 排序规则解析
0625~<config>-<bus>
Flink operation Hudi data table
可撤销并查集板子
Custom web framework
How to follow the "low coupling" design principle?
0627~ holiday knowledge summary
Three ways of redis cluster
数组对象方法 常用遍历方法&高阶函数
0615 ~ realize RBAC permission management with user-defined annotations
树链剖分板子
CF Lomsat gelral(启发式合并)
Go to bed capacity exchange
2022 the latest short video de watermarking analysis API interface sharing
【OpenCV】—阈值化
redis集群的三种方式
0629 ~ SaaS platform design ~ global exception handling
steam API
IO multiplexing
Admin component