| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Functions | [Back] [Original] |
Get to know MDN better
() (function body)
Function Function Function typeof "object" "function"
return return undefined return 1 1
:
new
(parameter) (argument) MDN web docs
function formatNumber(num) {
return num.toFixed(2);
}
formatNumber(2);
num (parameter) num JavaScript formatNumber(2) 2 (argument) arguments
function updateBrand(obj) {
//
obj.brand = "Toyota";
//
obj = null;
}
const car = {
brand: "Honda",
model: "Accord",
year: 1998,
};
console.log(car.brand); // Honda
//
updateBrand(car);
// updateBrand car
console.log(car.brand); // Toyota
JavaScript 4
Generator yield Promise await AsyncGenerator await yield new Function.prototype typeof MyClass === "function"
//
const multiply = new Function("x", "y", "return x * y");
//
function multiply(x, y) {
return x * y;
} //
//
const multiply = function (x, y) {
return x * y;
};
//
const multiply = function funcName(x, y) {
return x * y;
};
//
const multiply = (x, y) => x * y;
//
const obj = {
multiply(x, y) {
return x * y;
},
};
Function() function function new function Function() arguments this Function() Function() function
const y = function x() {};
console.log(x); // ReferenceError: x is not defined
new Function console.log(new Function().toString())
function anonymous(
) {
}
Function() anonymous
new Function("alert(anonymous);")();
Function
// p
globalThis.p = 5;
function myFunc() {
// p
const p = 9;
function decl() {
console.log(p);
}
const expr = function () {
console.log(p);
};
const cons = new Function("\tconsole.log(p);");
decl();
expr();
cons();
}
myFunc();
// Logs:
// 9 'decl'
// 9 'expr'
// 5 'cons'
Function new Function(...) Function
//
function foo() {
console.log("FOO!");
}
doSomething(
//
function foo() {
console.log("FOO!");
},
);
function async function IIFE
function () { // SyntaxError: Function statements require a function name
console.log("FOO!");
}();
function foo() {
console.log("FOO!");
}(); // SyntaxError: Unexpected token ')'
function void
(function () {
console.log("FOO!");
})();
void function () {
console.log("FOO!");
}();
function myFunc(a, b, c) {
// a, b, c
}
3
function myFunc({ a, b }, c = 1, ...rest) {
// a, b, c, rest
}
"use strict" arguments arguments.callee Object.getOwnPropertyDescriptor() API
"use strict";
function f() {
return 1;
}
{
function f() {
return 2;
}
}
f() === 1; // true
// f() === 2
if (shouldDefineZero) {
function zero() {
// :
console.log("");
}
}
zero if shouldDefineZero false zero function
// var
//
var zero;
if (shouldDefineZero) {
zero = function () {
console.log("");
};
}
//
function padZeros(num, totalLen) {
let numStr = num.toString(); //
const numZeros = totalLen - numStr.length; //
for (let i = 1; i <= numZeros; i++) {
numStr = `0${numStr}`;
}
return numStr;
}
padZeros
let result;
result = padZeros(42, 4); // "0042"
result = padZeros(42, 2); // "42"
result = padZeros(5, 4); // "0005"
typeof window noFunc
if (typeof window.noFunc === "function") {
// noFunc()
} else {
//
}
if noFunc "()"
| ECMAScript 2027 LanguageSpecification # sec-function-definitions |
| Web Proxy Viewer | New URL | Original Page |