<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>进击的巨人--JS</title>
<script>
/*var h="haha";*/
var name="鱼C根部";
var address=null;
//函数的定义
function first_function(){
name=name+" 守护鱼C黑夜的组织";
address="快来加入吧~";
}
//函数的调用
first_function();
alert("鱼C神秘组织:"+name+"广邀豪杰:"+address);
alert(h);
</script>
</head>
<body>
</body>
</html> 交!作!业!
误打误撞发现了换行符{:10_282:}
<!DOCTYPE html>
<html>
<head>
<title>007</title>
<meta charset='utf-8' http-equiv='Content-type' content='text/html'>
<script type="text/javascript">
var name1 = '鱼C根部';
name2 = '守护鱼C黑夜的组织'
function frist_function(){
addr = ' \n快来加入吧~!';
words = name1 + '、' + name2 + addr;
}
frist_function();
alert(words);
alert('name1 ---->' + name1);
alert('name2 ---->' + name2);
alert('addr ---->' + addr);
alert('words ---->' + words);
</script>
</head>
<body>
</body>
</html> {:5_91:} <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>title</title>
<script type="text/javascript">
name = 'Anthony';
function first_function(argument) {
name += "New York";
address="The Empire State";
}
var hahah = "看看定义在后面能不能用~"
first_function();
alert("New York's Boss "+name+"address: "+address);
alert(hahah);
//var hahah = "看看定义在后面能不能用~"
</script>
</head>
<body>
</body>
</html> {:10_256:}分清全局变量和局部变量,并可以使用 typeof 来查看变量是否定义
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
var name="鱼C根部";
// 定义
function first_function(){
name=name+"守护鱼C黑夜的组织";
address = "快来加入吧~";
}
// 调用
first_function();
alert("鱼C神秘组织:"+name+" 广邀豪杰:" +address);
/* alert(hahaha); */ //未定义会报错
/* 给hahaha进行赋值再执行试试 */
var hahaha = "这下我有定义了";
alert(hahaha);
</script>
</body>
</html> 为什么这里的address变量在函数调用完了之后没有被释放掉呢。。
页:
[1]