Files
ClassContent/历届学生/罗朝/2019-05-04/function.html
2024-09-27 02:06:13 +08:00

82 lines
1.7 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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>function</title>
</head>
<body>
<script>
// 定义了一个方法
function getUsername(price,color) {
var newcart = "你给了我"+ price + "万元钱,你想买"+color+"色的车!!";
return newcart
}
// 使用 函数名()
//getUsername()
// 函数名() 表示立即执行函数里面的代码
// 函数名 表示 把函数里面的所有代码块 作为参数赋值给其他的变量
// var names = getUsername;
// names()
// 方法 分为两类:
// 按照参数进行分类
// 1: 无参函数
// 2: 有参函数
let mycart = getUsername(120,'黑');
console.log(mycart);
// 按照是否具有函数名分类
// 1:匿名函数
// 2:正常的函数
// var getcart = function () {
// console.log("获取车的函数");
// }
// function getcart () {
// console.log("获取车的函数");
// }
// getcart()
// var a = 1;
// // var b = 2
// function carts () {
// var b = 2;
// // b = 2;
// console.log(b)
// }
// console.log(a) // 1
// carts() // 2
// console.log(b) // 2
// 定义在函数内部的变量,他是那个函数独有的,作用域仅限在函数内部使用,外部无法使用
// 变量 有作用域
// 局部作用域(变量)
// 全局作用域(变量)
// 当不使用var来定义变量的时候浏览器会把变量进行变量提升提升到全局
</script>
</body>
</html>