Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F7535244
test_block_function_hoisting.cjs
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
test_block_function_hoisting.cjs
View Options
// Test function declaration hoisting inside blocks
// Function declarations should be hoisted to the top of their containing block
console.log("=== Test 1: Function declaration hoisted in regular block ===");
{
foo();
function foo() {
console.log("foo called - hoisted in block");
}
}
console.log("\n=== Test 2: Function hoisting in arrow function body ===");
const test2 = () => {
bar();
function bar() {
console.log("bar called - hoisted in arrow function");
}
};
test2();
console.log("\n=== Test 3: Function hoisting in callback ===");
const arr = [1];
arr.forEach((x) => {
baz();
function baz() {
console.log("baz called with", x, "- hoisted in callback");
}
});
console.log("\n=== Test 4: Function hoisting in .map() callback ===");
const result = [5].map((x) => {
return helper(x);
function helper(n) {
return n * 2;
}
});
console.log("result should be [10]:", result);
console.log("\n=== Test 5: Nested function calling before definition ===");
function outer() {
inner();
function inner() {
console.log("inner called - hoisted inside outer");
}
}
outer();
console.log("\n=== Test 6: Function modifying outer variable before definition ===");
function test6() {
let value = 0;
modify();
console.log("value after modify should be 42:", value);
function modify() {
value = 42;
}
}
test6();
console.log("\n=== All block function hoisting tests completed ===");
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jun 17, 12:02 PM (1 d, 22 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
523679
Default Alt Text
test_block_function_hoisting.cjs (1 KB)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment