Skip to content

Commit 5103524

Browse files
Added Get Function Code
1 parent 7e85b08 commit 5103524

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Get_Function_Code.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
function getFunctionCode(functionName) {
3+
return typeof functionName === "function" ? functionName.toString() : "The argument is not a function.";
4+
}
5+
6+
// Example
7+
function Add(a, b) {
8+
return a + b;
9+
}
10+
function Subtract(x, y) {
11+
return x - y;
12+
}
13+
14+
// Using custom function
15+
console.log(getFunctionCode(Add));
16+
17+
// Using built-in function
18+
console.log(Subtract.toString());

0 commit comments

Comments
 (0)