wip: add more questions

chore/javascript
Arik Chakma 1 year ago
parent 802b84ad79
commit b39de5f670
  1. 20
      src/data/question-groups/javascript/content/heap-and-stack.md
  2. 25
      src/data/question-groups/javascript/javascript.md

@ -0,0 +1,20 @@
The Head and Stack in JavaScript Engine are two different data structures that store data in different ways.
## Stack
The Stack is a small, organized region of memory. It is where primitive values, function calls, and local variables are stored. It follows a "Last In, First Out" (LIFO) order, meaning that the last item added to the stack is the first one to be removed. Each function invocation creates a new stack frame, which contains the function's local variables, return address, and other contextual data.
## Heap
The Heap is a large, mostly unstructured region of memory. It is where `objects`, `arrays`, and `functions` are stored. Variables from the Stack (e.g., in functions) point to locations in the Heap for these dynamically allocated structures.
When you declare a primitive type (like a number or boolean), it's usually managed in the stack. But when you create an object, array, or function, it's stored in the heap, and the stack will hold a reference to that location in the heap.
For example:
```js
const name = 'JavaScript'; // Stored on the stack
const roadmap = { name: 'JS' }; // `roadmap` reference on the stack, actual object { name: 'JS' } in the heap
```
In the code above, the primitive value `JavaScript` for variable `name` is directly stored on the stack. For the object assigned to `roadmap`, its actual data resides in the heap, and the reference to this data (a memory address pointer) is held on the stack.

@ -298,4 +298,29 @@ questions:
topics:
- 'Core'
- 'Advanced'
- question: Is it possible to run JavaScript outside the browser?
answer: Yes, it is possible to run JavaScript outside the browser. There are several ways to run JavaScript outside the browser. You can use **Node.js**, **Deno**, **Bun**, or any other JavaScript runtime environment.
topics:
- 'Core'
- 'Beginner'
- question: Is it possible to run 2 lines of code at the same time in JavaScript?
answer: No, it is not possible to run 2 lines of code at the same time in JavaScript. JavaScript is a single-threaded language, which means that it can only execute one line of code at a time. However, it is possible to run 2 lines of code at the same time using asynchronous code.
topics:
- 'Core'
- 'Beginner'
- question: Is JavaScript a compiled or interpreted language?
answer: JavaScript is an interpreted language. This means that the JavaScript code is not compiled before it is executed. Instead, the JavaScript engine interprets the code at runtime.
topics:
- 'Core'
- 'Beginner'
- question: Are references copied in JavaScript?
answer: No, references are not copied in JavaScript. When you assign an object to a variable, the variable will contain a reference to the object. If you assign the variable to another variable, the second variable will also contain a reference to the object. If you change the object using one of the variables, the change will be visible using the other variable.
topics:
- 'Core'
- 'Intermediate'
- question: What are Heap and Stack in JavaScript?
answer: heap-and-stack.md
topics:
- 'Core'
- 'Advanced'
---

Loading…
Cancel
Save