js---06函数传参数

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>

<script>
/*
    参数=JS的数据类型:
        数字、字符串、布尔、函数、对象、未定义
*/

fn2('妙味课堂');
function fn2(a){
    alert(a.charAt(2));
}

function fn4(){
    alert(4);
}
function fn3( fn ){
    fn();
}
fn3( fn4 );

function fn3( fn ){
    fn(100);
}
fn3( function ( a ){ alert(a); } );//a=100

fn5( window, document );
function fn5( w, d ){
    w.onload = function (){
        d.body.innerHTML = 123;
    };
}

</script>

</head>

<body>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>

<script>

function fn1(a){
    if( typeof a === 'number' && a === a ){//a === a,NaN也是数字类型,NaN不等于自己,这是排除NaN
        alert( a+20 );
    } else if ( typeof a === 'string' ) {
        alert( a.charAt(2) );
    } else if ( typeof a === 'function' ) {
        a(100);//alert(101)
    }
}

fn1(100);
fn1('miaov');
fn1(function (arr){ alert(1+arr); });
</script>

</head>

<body>
</body>
</html>
原文地址:https://www.cnblogs.com/yaowen/p/6828757.html