Bird
Raised Fist0
Javascriptprogramming~5 mins

JavaScript runtime overview - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What is a JavaScript runtime?
A JavaScript runtime is an environment where JavaScript code runs. It provides tools like memory management, event handling, and APIs to interact with the system or browser.
Click to reveal answer
beginner
Name two popular JavaScript runtimes.
Two popular JavaScript runtimes are the browser (like Chrome's V8 engine) and Node.js, which runs JavaScript outside the browser.
Click to reveal answer
intermediate
What role does the event loop play in the JavaScript runtime?
The event loop manages asynchronous tasks by checking the message queue and executing callbacks when the call stack is empty, allowing non-blocking code execution.
Click to reveal answer
beginner
What is the call stack in a JavaScript runtime?
The call stack keeps track of function calls. It follows last-in, first-out order, running the top function and removing it when done before moving to the next.
Click to reveal answer
intermediate
How does Node.js differ from browser JavaScript runtime?
Node.js provides extra APIs for file system, networking, and more, allowing JavaScript to run on servers, while browsers focus on web page interaction and DOM manipulation.
Click to reveal answer
What does the JavaScript event loop do?
AManages asynchronous tasks and executes callbacks
BCompiles JavaScript code to machine code
CStores variables and functions
DHandles user interface rendering
Which of these is NOT a JavaScript runtime?
AChrome browser
BPython interpreter
CNode.js
DV8 engine
Where does JavaScript run in a browser?
AIn the operating system kernel
BIn the call stack only
COn the server only
DInside the JavaScript runtime environment
What is the call stack used for?
AManaging asynchronous events
BStoring global variables
CTracking function calls in order
DRendering HTML elements
Which API is available in Node.js but NOT in browsers?
AFile system access
BsetTimeout
CDOM manipulation
Dconsole.log
Explain the main components of a JavaScript runtime and how they work together.
Think about how JavaScript runs code and handles tasks that take time.
You got /4 concepts.
    Describe the differences between running JavaScript in a browser and in Node.js.
    Consider what each environment allows JavaScript to do.
    You got /4 concepts.

      Practice

      (1/5)
      1. What is the main role of the JavaScript runtime environment?
      easy
      A. To compile JavaScript into machine code before running
      B. To design the user interface of a web page
      C. To execute JavaScript code and provide necessary tools
      D. To store JavaScript files on the server

      Solution

      1. Step 1: Understand what a runtime environment does

        The runtime environment is where JavaScript code runs and interacts with other parts like APIs and event loop.
      2. Step 2: Identify the main role

        Its main role is to execute JavaScript code and provide tools like APIs and event handling.
      3. Final Answer:

        To execute JavaScript code and provide necessary tools -> Option C
      4. Quick Check:

        Runtime runs code and tools = B [OK]
      Hint: Runtime runs code and tools, not UI or storage [OK]
      Common Mistakes:
      • Confusing runtime with compiler
      • Thinking runtime designs UI
      • Assuming runtime stores files
      2. Which of the following is the correct way to access the global object in a JavaScript runtime?
      easy
      A. globalThis
      B. window
      C. document
      D. runtime

      Solution

      1. Step 1: Recall the global object in modern JavaScript

        The global object is accessible via globalThis in all environments.
      2. Step 2: Compare options

        window is global in browsers only, document is for DOM, runtime is not a valid object.
      3. Final Answer:

        globalThis -> Option A
      4. Quick Check:

        Universal global object = globalThis [OK]
      Hint: Use globalThis for universal global access [OK]
      Common Mistakes:
      • Using window in non-browser environments
      • Confusing document with global object
      • Assuming runtime is a global object
      3. What will the following code output in a typical JavaScript runtime?
      console.log(typeof setTimeout);
      medium
      A. "undefined"
      B. "function"
      C. "object"
      D. "number"

      Solution

      1. Step 1: Understand what setTimeout is

        setTimeout is a timer API function provided by the runtime environment.
      2. Step 2: Determine the type of setTimeout

        Since setTimeout is a function, typeof setTimeout returns "function".
      3. Final Answer:

        "function" -> Option B
      4. Quick Check:

        setTimeout is a function = "function" [OK]
      Hint: setTimeout is a function, so typeof returns "function" [OK]
      Common Mistakes:
      • Thinking setTimeout is undefined
      • Confusing setTimeout with a number
      • Assuming setTimeout is an object
      4. Identify the error in this code snippet related to JavaScript runtime APIs:
      setTimeout(() => {
        console.log('Hello');
      }, '1000');
      medium
      A. The delay should be a number, not a string
      B. Arrow functions cannot be used with setTimeout
      C. console.log is not available in runtime
      D. setTimeout requires three arguments

      Solution

      1. Step 1: Check the setTimeout parameters

        setTimeout expects the delay as a number, but here it is a string '1000'.
      2. Step 2: Understand the impact

        Passing a string may cause the delay to be treated as 0 or converted, which is incorrect usage.
      3. Final Answer:

        The delay should be a number, not a string -> Option A
      4. Quick Check:

        Delay must be number, not string [OK]
      Hint: Delay argument must be a number, not a string [OK]
      Common Mistakes:
      • Using string instead of number for delay
      • Thinking arrow functions are invalid here
      • Assuming console.log is unavailable
      5. You want to run a piece of JavaScript code repeatedly every 2 seconds using the runtime environment. Which code snippet correctly achieves this?
      hard
      A. repeat(() => console.log('Repeat'), 2000);
      B. setTimeout(() => console.log('Repeat'), 2000);
      C. while(true) { console.log('Repeat'); }
      D. setInterval(() => console.log('Repeat'), 2000);

      Solution

      1. Step 1: Identify the correct API for repeated execution

        setInterval runs a function repeatedly at specified intervals.
      2. Step 2: Compare options

        setTimeout runs once, while loop blocks execution, and repeat is not a valid function.
      3. Final Answer:

        setInterval(() => console.log('Repeat'), 2000); -> Option D
      4. Quick Check:

        Repeated runs use setInterval [OK]
      Hint: Use setInterval for repeated actions every interval [OK]
      Common Mistakes:
      • Using setTimeout for repeated calls
      • Using infinite while loop causing freeze
      • Assuming repeat is a valid function
      Recommended

      Ready to prove it?

      Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

      10 questions~5 mineasy hard