We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
关键词:函数声明、函数表达式
JavaScript中有两种主要的方式来定义函数:函数声明(Function Declaration)和函数表达式(Function Expression)。
function
示例:
function sayHello() { console.log("Hello!"); } sayHello(); // 可以在函数声明之后调用
// 匿名函数表达式 const sayHello = function() { console.log("Hello!"); }; sayHello(); // 必须在函数表达式之后调用 // 具名函数表达式 const add = function sum(a, b) { return a + b; }; console.log(add(2, 3)); // 输出: 5 // console.log(sum(2, 3)); // 错误,无法在外部访问具名函数表达式的名称
总结:
The text was updated successfully, but these errors were encountered:
No branches or pull requests
关键词:函数声明、函数表达式
JavaScript中有两种主要的方式来定义函数:函数声明(Function Declaration)和函数表达式(Function Expression)。
function
关键字后面跟着函数名称来创建的,通常位于作用域的顶部。示例:
示例:
总结:
function
关键字创建的函数,会被提升,可以在声明之前调用,而且在整个作用域内都可访问。The text was updated successfully, but these errors were encountered: