Predict Execution Order
Predict Output Easy
Question
What does this code print?
Code
console.log("A");
function foo() {
console.log("C");
}
console.log("B");
foo();
console.log("D");
Hint
Functions are defined but not run until called.
Explanation
Code executes top-to-bottom. First "A" is printed. Then foo is defined (but not called yet). Then "B" is printed. Then foo() is called, printing "C". Then "D" is printed. The output is: A, B, C, D (each on its own line).
Related Resources
Related Lessons
- How Programs Work
Learn how programs work.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.