1 Star 0 Fork 0

白龙马 / HTML-CSS-JS

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
13JS函数.html 2.62 KB
一键复制 编辑 原始数据 按行查看 历史
白龙马 提交于 2024-02-23 08:28 . 第一次上传gitee十四
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>13 JavaScript 函数</title>
</head>
<body>
<h1>13 JavaScript 函数</h1>
<h2>1 无参数,无返回值的函数</h2>
<pre>
function hello(){
console.log('Hello JavaScript!');
}
hello();
</pre>
<h2>2 无参数,有返回值的函数</h2>
<pre>
function hello01() {
return 'Return Hello JavaScript!';
}
let hell = hello01();
console.log(hell);
</pre>
<h2>3 有参数,无返回值的函数</h2>
<pre>
function hello10(name) {
console.log('Hello ' + name + '!');
}
hello10('BlMa');
hello10('5217');
</pre>
<h2>4 有参数,有返回值的函数</h2>
<pre>
function hello11(name) {
return 'Return Hello ' + name + '!';
}
let he11 = hello11('白龙马');
console.log(he11);
</pre>
<h2>5 变量作用域</h2>
函数外声明的变量为全局变量,函数内声明的变量为局部变量,函数内可以访问外部全局变量,函数外不能访问函数内的语句变量。
<pre>
let gs = '全局变量';
function func2() {
let ls = '局部变量';
console.log(gs);
console.log(ls);
}
console.log(gs);
// console.log(ls); //这里会报错
func2();
</pre>
</body>
</html>
<script>
// 无参数,无返回值的函数
function hello00() {
console.log('Hello JavaScript!');
}
hello00();
// 无参数,有返回值的函数
function hello01() {
return 'Return Hello JavaScript!';
}
let hell = hello01();
console.log(hell);
// 有参数,无返回值的函数
function hello10(name) {
console.log('Hello ' + name + '!');
}
hello10('BlMa');
hello10('5217');
// 有参数,有返回值的函数
function hello11(name) {
return 'Return Hello ' + name + '!';
}
let he11 = hello11('白龙马');
console.log(he11);
// 变量作用域
let gs = '全局变量';
function func2() {
let ls = '局部变量';
console.log(gs);
console.log(ls);
}
console.log(gs);
// console.log(ls); //这里会报错
func2();
</script>
HTML
1
https://gitee.com/blma/html-css-js.git
git@gitee.com:blma/html-css-js.git
blma
html-css-js
HTML-CSS-JS
master

搜索帮助