Javascript Process Flow

> The JavaScript Execution Model (Simplified)

1. **Line-by-line execution** (Synchronous)

In JavaScript:

console.log("A"); sayHello(); console.log("C"); function sayHello() { console.log("B"); }

This will output:

A B C

Execution is **linear and synchronous** by default. Like LiveCode, each line runs in order **until a function is called**. When that happens: * Control **jumps** to the function body * Executes it **in full** * Returns to the next line after the call Very much like `send "doStuff" to button "X"` in LiveCode—except JavaScript is function-oriented rather than UI-object-oriented.

# Quick Comparison: LiveCode vs JavaScript | Concept | LiveCode | JavaScript | | ------------------------- | --------------------------------- | ------------------------------------- | | Basic Execution | Line-by-line | Line-by-line | | Function/Command Call | Message path through objects | Call stack | | Asynchronous behavior | `send in time` | `setTimeout`, Promises, async/await | | Closures / retained scope | Custom properties / globals | Closures (`function() { ... }`) | | Anonymous Functions | Rare / not inline | Common (especially for callbacks) | | Event System | Built-in to message-passing model | Handled with `addEventListener`, etc. |

# TL;DR * ✅ JavaScript is synchronous by default—functions jump and return as you'd expect * 🌀 Asynchronous behavior (timeouts, network calls, etc.) doesn't block the main thread—it's queued and executed later * 🔁 Closures allow functions to remember state—like custom command handlers with internal data * ⚠️ Anonymous and async functions can make code seem out-of-order, but it follows strict rules (event loop + call stack)

# See