MAD Study Hub

Home / Past papers / MAD2 End Term / this paper

IIT M FOUNDATION DIPLOMA AN EXAM QDF4 28 Apr 2024 - 28 Apr 2024

MAD2 End Term32 questions100 marks25 MCQ · 7 MSQFoundation / Diploma / afternoon / QDF4
Elapsed 00:00
Q1MCQ2 marks
question figure
Text of the picture (copyable)
Consider the following Script embedded in an HTML document.

```javascript
let langName = 'Python';
function showLanguage() {
    let langName = "JavaScript";
    let message = 'Learn ' + langName;
    console.log(message);
}

let message = 'Learn ' + langName;
console.log(message)
console.log(showLanguage());
```

What will be the output on console, if the HTML document is rendered using a browser?
  1. question figure
    text
    Learn JavaScript
    Learn Python
  2. question figure
    text
    Learn JavaScript
    Learn JavaScript
    undefined
  3. question figure
    text
    Learn Python
    Learn JavaScript
  4. question figure
    text
    Learn Python
    Learn JavaScript
    undefined
Q2MCQ2 marks
question figure
Text of the picture (copyable)
Consider the following Script embedded in an HTML document.

```javascript
let x = [1, 'p', a => a + 1];

for (const i = 0; i<x.length; i++) {
    console.log(i, x[i], typeof(x[i]))
}
```

Which of the following statement is correct, if the HTML document is rendered using a browser?
  1. It will throw error on the console for the very first iteration.
  2. It will display the index, value and type of the value for the first item of arrayand then will throw error for the next value.
  3. It will display the indices, values and types of all the items of the array.
  4. None of these.
Q3MCQ2 marks
question figure
Text of the picture (copyable)
Assuming the URL gives a valid json response, what will be the output in the console?

```javascript
fetch('https://study.iitm.ac.in/api/data')
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error(error));

console.log('End of script');
```
  1. The JSON data from the specified URL followed by “End of script”.
  2. "End of script" will be logged first, followed by the JSON data.
  3. An error will be logged, and the script will terminate.
  4. "End of script" will be logged, but the JSON data retrieval will fail.
Q4MCQ2 marks
Which of the following statements is false regarding JavaScript and its behavior?
  1. The language supports both first class and higher order functions.
  2. The language supports higher order functions, but not first class functions.
  3. A variable declared without keywords “var”, “let” or “const” is not hoisted at all.
  4. The variables declared using keywords “let” and “const” are also hoisted.
Q5MCQ2 marks
Where is system state commonly stored in a web application?
  1. Client Side local storage
  2. In Memory Cache
  3. Session Cookies
  4. Server Side Database
Q6MCQ2 marks
Which technology is commonly used to manage application state in a Vue.js application?
  1. Vue.js
  2. React.js
  3. Vuex
  4. Redux
  5. Express.js
  6. Angular
Q7MSQ3 marksselect all that apply
question figure
Text of the picture (copyable)
Consider the following Script embedded in an HTML document.

```javascript
let myQual = {
    degree: "B-tech",
    college: "IIT Delhi",
    get qualification(){
        return `degree: ${this.degree}, college: ${this.college}`
    },
    set qualification(q){
        let components = q.split(' ');
        this.degree = components[0];
        this.college = components[1];
    }
}
```

Which of the following statements will throw an error on the console when the HTML document is rendered using a browser?
  1. question figure
    text
    ```javascript
    console.log(myQual.qualification())
    ```
  2. question figure
    text
    ```javascript
    console.log(myQual.qualification)
    ```
  3. question figure
    text
    ```javascript
    console.log(myQual.qualification = 'M-tech IIT-Madras')
    ```
  4. question figure
    text
    ```javascript
    console.log(myQual.qualification('M-tech IIT-Madras'))
    ```
Q8MSQ3 marksselect all that apply
question figure
Text of the picture (copyable)
Consider the following two HTML documents and the Vue app created in script.js file and select the correct option(s).

index1.html
```html
<body>
    <div id="app">
        <h1 v-if="result">Hello am I visible?</h1>
    </div>
    <script src="./script.js"></script>
</body>
```

index2.html
```html
<body>
    <div id="app">
        <h1 v-show="final">Hello am I visible?</h1>
    </div>
    <script src="./script.js"></script>
</body>
```

script.js
```javascript
var app = new Vue({
    el: '#app',
    data: {
        result: false,
        final: false
    }
})
```
  1. question figure
    text
    The raw HTML created with index1.html and index2.html will be exactly the same
    for the current state of data.
  2. question figure
    text
    When the directive v-if is falsy, it removes the entire element from the DOM.
  3. question figure
    text
    When the directive v-show is falsy, it removes the entire element from the DOM.
  4. question figure
    text
    The raw HTML created with index1.html and index2.html will be exactly the same when the values of both "result" and "final" are set to true.
Q9MSQ3 marksselect all that apply
question figure
Text of the picture (copyable)
Consider the following Vue application and the rendered HTML output below.

Filename: script.js

```javascript
var app = new Vue({
  el: '#app',
  data: {
    items: [
      {id: 1, name:"mad 1"},
      {id: 2, name:"mad 2"},
      {id: 3, name:"mad 3"}
    ]
  }
})
```

Rendered output:
mad 1
mad 2
mad 3

What should be the content of `<div id = "app"></div>` in index.html that generates the given rendered output?
  1. question figure
    text
    ```html
    <h2 v-for="item in items">{{item.name}}</h2>
    ```
  2. question figure
    text
    ```html
    <h2 v-for="item in items">{{item.id}}>{{item.name}}</h2>
    ```
  3. question figure
    text
    ```html
    <h2 v-for="item in items" :id="item.id">{{item.name}}</h2>
    ```
  4. question figure
    text
    ```html
    <h2 v-for="items" :id="item.id">item.name</h2>
    ```
Q10MSQ3 marksselect all that apply
Which of the following HTTP status code(s) is/are commonly used in RESTful APIs for successful responses?
  1. 200
  2. 201
  3. 400
  4. 404
  5. 500
Q11MSQ3 marksselect all that apply
Which of the following is/are potential benefit(s) of using caching in web applications?
  1. Reduced latency and faster response times
  2. Lower server load and reduced bandwidth usage
  3. Improved scalability and better handling of traffic spikes
  4. Enhanced security and protection against DDoS attacks
Q12MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following Script embedded in an HTML document.

```javascript
class Twowheeler {
  constructor(name) {
    this.name = name;
    this.gear = 4;
    this.seating = 2;
  }

  get description() {
    return `${this.name} has ${this.gear} gear and has ${this.engine} engine.`;
  }
}

class Moped extends Twowheeler {
  constructor(name) {
    super(name);
    this.engine = '4 stroke';
  }
}

let myBike = new Twowheeler("Discover");
let myDrive = new Moped("Activa");
console.log(myDrive.description);
console.log(myBike.description);
```

What will be the output on console, if the HTML document is rendered using a browser?
  1. question figure
    text
    ```
    Discover has 4 gear and has 4 stroke engine.
    Activa has 4 gear and has 4 stroke engine.
    ```
  2. question figure
    text
    ```
    Activa has 4 gear and has undefined engine.
    Discover has 4 gear and has 4 stroke engine.
    ```
  3. question figure
    text
    ```text
    Activa has 4 gear and has 4 stroke engine.
    Discover has 4 gear and has undefined engine.
    ```
  4. question figure
    text
    ```text
    Discover has 4 gear and has undefined engine.
    Activa has 4 gear and has undefined engine.
    ```
Q13MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following Script embedded in an HTML document.

```javascript
function parentFunc(name) {
  return {
    sayHello: () => "Hi! " + name,
    sayBye: () => "Bye! " + name,
    changeName: (newName) => {
      name = newName;
    },
  };
}

const arpan = parentFunc("Arpan");
const beli = parentFunc("Beli");

console.log(arpan.sayHello());
console.log(beli.sayHello());
arpan.changeName("Beli");
console.log(arpan.sayBye());
```

What will be the output on console, if the HTML document is rendered using a browser?
  1. question figure
    text
    ```
    Hi! Arpan
    Bye! Arpan
    ```
  2. question figure
    text
    ```
    Hi! Arpan
    Hi! Beli
    Bye! Beli
    ```
  3. question figure
    text
    ```
    Hi! Arpan
    reference Error
    ```
  4. question figure
    text
    Reference Error
Q14MCQ3 marks
question figure
Text of the picture (copyable)
What will be the text displayed in a web page if the Vue app given below is running
in a development mode?

Filename: index.html

```html
<div id="app1">
    <h1>{{ title }}</h1>
    <h4>{{ greetings() }}</h4>
</div>
<div id="app2">
    <h1>{{ title }}</h1>
    <h4>{{ greetings }}</h4>
</div>
```

Filename: app.js

```javascript
new Vue({
    el: "#app1",
    data: { title: "App No 1" },
    computed: {
        greetings() {
            return "hello from " + this.title;
        },
    },
});

new Vue({
    el: "#app2",
    data: { title: "App No 2" },
    computed: {
        greetings() {
            return "hello from " + this.title;
        },
    },
});
```
  1. question figure
    text
    App No 1
    hello from App No 1
    
    App No 2
    hello from App No 2
  2. question figure
    text
    App No 2
    hello from App No 2
  3. question figure
    text
    App No 1
    App No 2
  4. question figure
    text
    Blank page
Q15MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following Script embedded in an HTML document.

```javascript
var var1 = 25;
var var2 = 35;

const myObj = {
    var2: 45,
    var1: 35,
    ObjFunc: function(var3){
        let var4 = var3**2;
        return 10 + this.var2 + var4;
    }
}

let m = myObj.ObjFunc
console.log(m.bind()(5))
console.log(m.call(myObj,6))
```

What will be the output on console, if the HTML document is rendered using a browser?
  1. question figure
    text
    ```
    70
    81
    ```
  2. question figure
    text
    ```
    70
    91
    ```
  3. question figure
    text
    ```
    80
    81
    ```
  4. question figure
    text
    ```
    80
    91
    ```
Q16MCQ3 marks
What does the “finally” method do in promises?
  1. The method is executed when the promise is fulfilled.
  2. The method is executed when the promise is rejected.
  3. The method is executed regardless of whether the promise is fulfilled orrejected.
  4. The method can not be used with promises at all.
Q17MCQ3 marks
Which of the following statements regarding Celery task execution is correct?
  1. Celery tasks are executed synchronously by default.
  2. Celery tasks can only be executed on the same machine where the flaskapplication is running.
  3. Celery tasks are executed asynchronously by default.
  4. Celery tasks can only be executed once they are defined as part of a flaskapplication.
Q18MCQ3 marks
What is the primary objective of using a message broker?
  1. Eliminates the need for network communication
  2. Decouples producers and consumers
  3. Decreases CPU utilization
  4. Reduces the need for data serialization
Q19MCQ3 marks
In a message broker system, what does the term "topic" refer to?
  1. The physical location where messages are stored.
  2. A unique identifier for a message.
  3. The process of encrypting messages.
  4. A channel to which messages are published.
Q20MCQ3 marks
What is the primary advantage of using server-sent events over traditional polling?
  1. Server-sent events support bidirectional communication.
  2. Server-sent events can handle larger payloads.
  3. Server-sent events reduce server load by eliminating the need for frequentpolling.
  4. Server-sent events provide lower latency compared to polling.
Q21MCQ3 marks
Which of the following protocols is commonly used for implementing polling?
  1. HTTP
  2. Web Sockets
  3. FTP
  4. SMTP
Q22MCQ3 marks
What is the primary purpose of CORS in web security?
  1. To prevent unauthorized access to confidential data
  2. To mitigate cross-site scripting (XSS) attacks
  3. To enable controlled access to resources from different origins
  4. To protect against SQL injection attacks
Q23MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following Script embedded in an HTML document.

```javascript
let obj1 = {
    subject: 'Mechanics',
    stream: 'Physics'
}

let obj2 = obj1;
let obj3 = {};

for (let key in obj1){
    obj3[key] = obj1[key];
}

obj2.subject = 'Thermodynamics'
obj3.stream = 'Chemistry'

console.log(Obj1)
```

What will be the output on console, if the HTML document is rendered using a browser?
  1. question figure
    text
    ```
    {
        subject: 'Thermodynamics',
        stream: 'Physics'
    }
    ```
  2. question figure
    text
    ```
    {
        subject:'Mechanics',
        stream:'Chemistry'
    }
    ```
  3. question figure
    text
    ```
    {
        subject: 'Mechanics',
        stream: 'Physics'
    }
    ```
  4. question figure
    text
    ```
    {
        subject:'Thermodynamics',
        stream:'Chemistry'
    }
    ```
Q24MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following Script embedded in an HTML document.

```javascript
var var1 = 25;

const exObj = {
    var2: 45,
    var1: 35,
    inObj : {
        var1: 45,
        inObjFunc: ()=>{
            return "Value is " + this.var1;
        }
    },
    exObjFunc: function(){
        let var2 = 10;
        return "Value is " + this.var2;
    }
}

let x = exObj.inObj
console.log(x.inObjFunc())
console.log(exObj.exObjFunc())
```

What will be the output on console, if the HTML document is rendered using a browser?
  1. question figure
    text
    ```
    Value is 35
    Value is 10
    ```
  2. question figure
    text
    ```
    Value is 35
    Value is 45
    ```
  3. question figure
    text
    Value is 25
    Value is 10
  4. question figure
    text
    ```
    Value is 25
    Value is 45
    ```
Q25MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following Script "script.js" embedded in an HTML document, "index.html" and an external script "app.js" given below.

Filename: index.html
```html
<html lang="en">
<head></head>
<body>
    <script src="./script.js"></script>
</body>
</html>
```

Filename: script.js
```javascript
function loadScript(src, cbf){
    let script = document.createElement('script');
    script.src = src;
    script.onload = () => cbf();
    document.head.append(script);
}

let cbf = function(){
    console.log("callback function executed here.");
    extFunc()
}

loadScript("./support_m6.js", cbf)
extFunc()
```

Filename: app.js
```javascript
console.log("Now I am loaded, let's support")

function extFunc(){
    console.log("loaded and run from external script")
}
```

What will be the output on console, if the HTML document is rendered using a browser?
  1. question figure
    text
    ```
    Now I am loaded, let's support
    callback function executed here.
    loaded and run from external script
    loaded and run from external script
    ```
  2. question figure
    text
    ```
    loaded and run from external script
    Now I am loaded, let's support
    callback function executed here.
    loaded and run from external script
    ```
  3. question figure
    text
    ```
    Now I am loaded, let's support
    callback function executed here.
    loaded and run from external script
    Uncaught ReferenceError: extFunc is not defined
    ```
  4. question figure
    text
    ```
    Uncaught ReferenceError: extFunc is not defined
    Now I am loaded, let's support
    callback function executed here.
    loaded and run from external script
    ```
Q26MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the below JavaScript program.

```javascript
Array.prototype.double = function (arr) {
  const res = [];
  for (let i=0; i<placeholder.length; i++)
    res.push(placeholder[i] * 2);
  return res;
}

const arr = [2, 3, 7, 8];
console.log(arr.double());
```

What of the following can be used in place of "placeholder" in the above program so that the program yields the below output array?
[ 4, 6, 14, 16 ]
  1. arr
  2. Array
  3. this
  4. The program cannot yield such an output, and is implemented in a wrong way.
Q27MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the below JavaScript program.

```javascript
const fetchData = (url) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      if (url.includes("success")) {
        resolve(`Data fetched successfully from: ${url}`);
      } else {
        reject(`Error fetching data: ${url}`);
      }
    }, 1000);
  });
};

const processData = (data) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(`Processed data: ${data.toUpperCase()}`);
    }, 500);
  });
};

const handleError = (error) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(`Handled Error: ${error}`);
    }, 300);
  });
};

fetchData("https://example.com/success")
  .then(processData)
  .then(fetchData)
  .then(handleError)
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });
```

What will be the output of the above program, if executed?
  1. question figure
    text
    Handled Error: Processed data: DATA FETCHED SUCCESSFULLY FROM:
    HTTPS://EXAMPLE.COM/SUCCESS
  2. question figure
    text
    Error fetching data: Processed data: DATA FETCHED SUCCESSFULLY FROM:
    HTTPS://EXAMPLE.COM/SUCCESS
  3. question figure
    text
    Handled Error: ERROR FETCHING DATA FROM: UNDEFINED
  4. question figure
    text
    Handled Error: ERROR FETCHING DATA FROM: HTTPS://EXAMPLE.COM/SUCCESS
  5. question figure
    text
    Error fetching data: Processed data: UNDEFINED
Q28MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following Vuex module definition for managing a shopping cart.

```javascript
const cartModule = {
  state: {
    items: []
  },
  mutations: {
    addItem(state, item) {
      state.items.push(item);
    },
  },
  actions: {
    async addToCart({ commit }, item) {
      // TODO: Implement adding item to cart
    },
  },
}
```

Which of the following options correctly completes the code for the "addToCart" action function?
  1. question figure
    text
    ```javascript
    addToCart({ commit }, item) {
      commit('addItem', item);
    }
    ```
  2. question figure
    text
    ```javascript
    addToCart({ state, commit }, item) {
      const existingItem = state.items.find(i => i.id === item.id);
      if (existingItem) {
        commit('addItem', existingItem);
      } else {
        commit('addItem', item);
      }
    }
    ```
  3. question figure
    text
    ```javascript
    addToCart({ commit }, item) {
      commit('addItem', { ...item });
    }
    ```
  4. question figure
    text
    All of these
Q29MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following Vue application with markup "index.html" and JavaScript file "app.js".

index.html:

```html
<div id = "app">
  <input v-model = "subject" @input = "compute_marks">
  <p> {{marks}} </p>
</div>
<script scr = "app.js"></script>
```

app.js:

```javascript
new Vue({
  el : "#app",
  data : {
    subject : "AppDev",
    marks : 50,
  },

  mounted () {
    this.subject = "AppDev";
    this.marks = 50;
    if (localStorage.marks) {
      this.subject += "1";
      this.marks = parseInt(localStorage.marks) + 20;
      localStorage.marks = this.marks;
      localStorage.subject = this.subject;
    }
    else {
      this.subject += "2";
      this.marks += 20;
    }
  },

  methods : {
    compute_marks() {
      localStorage.setItem("subject", this.subject);
      localStorage.setItem("marks", this.marks + 10);
    }
  }
})
```

Suppose you open "index.html" file in a browser, and type the text "EndTermExam" in the text box shown (after removing the previous text, if any), and hard refresh the page thrice, without clicking anywhere. What will be the value shown in the text box, and the "marks" placeholder, respectively?
  1. AppDev1, 120
  2. AppDev2, 120
  3. AppDev1, 140
  4. AppDev2, 140
Q30MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following Vue application with markup "index.html" and JavaScript file "app.js".

index.html:

```html
<div id="app">
  <router-link :to="{ name: 'user', params: { id: 'Jyoti' }}">User Profile</router-link>
  <router-view></router-view>
</div>
<script src="app.js"></script>
```

app.js:

```javascript
const UserProfile = {
  template: `
    <div>
      <h1>User Profile</h1>
      <p>User ID: {{ id }}</p>
    </div>
  `,
  props: ['id']
};

const routes = [
  { path: '/user/:id', name: 'user', component: UserProfile, props: true }
];

const router = new VueRouter({
  routes
});

new Vue({
  el: '#app',
  router,
});
```

Based on this setup, what will be displayed in the browser when the user clicks on the "User Profile" link?
  1. An error indicating that the id prop is not defined.
  2. User ProfileUser ID: Jyoti
  3. An error indicating that the data object is not defined.
  4. An error indicating that the route does not exist.
  5. User ProfileUser ID:
Q31MSQ2 marksselect all that apply
Which of the following is/are built in Vue.js lifecycle hook(s)?
  1. beforeLoad
  2. preUpdate
  3. mounted
  4. updated
Q32MSQ2 marksselect all that apply
Which of the following JavaScript method(s) is/are used to remove data from the session storage?
  1. clear()
  2. removeItem()
  3. deleteItem()
  4. unSet()

Answer key

  1. Q1 (MCQ, 2 marks): D
  2. Q2 (MCQ, 2 marks): B
  3. Q3 (MCQ, 2 marks): B
  4. Q4 (MCQ, 2 marks): B
  5. Q5 (MCQ, 2 marks): D
  6. Q6 (MCQ, 2 marks): C
  7. Q7 (MSQ, 3 marks): A, D
  8. Q8 (MSQ, 3 marks): B, D
  9. Q9 (MSQ, 3 marks): A, C
  10. Q10 (MSQ, 3 marks): A, B
  11. Q11 (MSQ, 3 marks): A, B, C
  12. Q12 (MCQ, 3 marks): C
  13. Q13 (MCQ, 3 marks): B
  14. Q14 (MCQ, 3 marks): B
  15. Q15 (MCQ, 3 marks): B
  16. Q16 (MCQ, 3 marks): C
  17. Q17 (MCQ, 3 marks): C
  18. Q18 (MCQ, 3 marks): B
  19. Q19 (MCQ, 3 marks): D
  20. Q20 (MCQ, 3 marks): C
  21. Q21 (MCQ, 3 marks): A
  22. Q22 (MCQ, 3 marks): C
  23. Q23 (MCQ, 4.5 marks): A
  24. Q24 (MCQ, 4.5 marks): D
  25. Q25 (MCQ, 4.5 marks): D
  26. Q26 (MCQ, 4.5 marks): C
  27. Q27 (MCQ, 4.5 marks): B
  28. Q28 (MCQ, 4.5 marks): A
  29. Q29 (MCQ, 4.5 marks): C
  30. Q30 (MCQ, 4.5 marks): B
  31. Q31 (MSQ, 2 marks): C, D
  32. Q32 (MSQ, 2 marks): A, B

Concepts this paper tests

Auto-generated summary from the source site. Handy as a checklist; the lessons above explain each idea from scratch.

Here’s a structured summary of core topics, concepts, and principles essential for the exam, along with a Mermaid knowledge graph to visualize relationships.


Core Topics & Concepts

1. JavaScript Fundamentals

Key Concepts:

Key Equations/Code Snippets:

// Hoisting Example
console.log(a); // undefined (var is hoisted)
var a = 5;

// Closure Example
function outer() {
  let x = 10;
  return function inner() { console.log(x); };
}
const innerFunc = outer();
innerFunc(); // 10

// `this` Binding
const obj = { val: 42, getVal: function() { return this.val; } };
console.log(obj.getVal.call({ val: 100 })); // 100

// Promise Example
fetch('url')
  .then(res => res.json())
  .catch(err => console.error(err))
  .finally(() => console.log("Done"));

2. Modern JavaScript (ES6+)

Key Concepts:

Key Equations/Code Snippets:

// Destructuring
const { a, b } = { a: 1, b: 2 };
const arr = [1, 2, 3];
const [x, ...rest] = arr; // x=1, rest=[2,3]

// Class Example
class Parent {
  constructor(name) { this.name = name; }
  greet() { return `Hello, ${this.name}`; }
}
class Child extends Parent {
  constructor(name) { super(name); }
}

// Module Export
export const foo = () => console.log("Foo");

3. Vue.js

Key Concepts:

Key Equations/Code Snippets:

// Vue Instance
new Vue({
  el: '#app',
  data: { message: 'Hello' },
  mounted() { console.log('Mounted!'); }
});

// Vuex Store
const store = new Vuex.Store({
  state: { count: 0 },
  mutations: {
    increment(state) { state.count++; }
  },
  actions: {
    incrementAsync({ commit }) {
      setTimeout(() => commit('increment'), 1000);
    }
  }
});

// Vue Router
const routes = [
  { path: '/user/:id', component: User, props: true }
];
const router = new VueRouter({ routes });

4. Web APIs & Asynchronous Patterns

Key Concepts:

Key Equations/Code Snippets:

// Fetch with Error Handling
fetch('https://api.example.com/data')
  .then(res => {
    if (!res.ok) throw new Error('HTTP error');
    return res.json();
  })
  .catch(err => console.error(err));

// Server-Sent Events
const eventSource = new EventSource('/updates');
eventSource.onmessage = (e) => console.log(e.data);

// WebSocket
const socket = new WebSocket('wss://example.com');
socket.onmessage = (e) => console.log(e.data);

5. Backend & State Management

Key Concepts:

Key Equations/Code Snippets:

// Local Storage
localStorage.setItem('key', 'value');
const data = localStorage.getItem('key');

// Session Storage
sessionStorage.removeItem('key');
sessionStorage.clear();

// CORS Headers (Server-Side)
response.setHeader('Access-Control-Allow-Origin', '*');

6. HTTP & RESTful APIs

Key Concepts:

Key Equations/Code Snippets:

### Successful Response
HTTP/1.1 200 OK
Content-Type: application/json

{ "id": 1, "name": "Example" }

### Error Response
HTTP/1.1 404 Not Found
Content-Type: application/json

{ "error": "Resource not found" }

7. Debugging & Error Handling

Key Concepts:

Key Equations/Code Snippets:

// Debugging Objects
console.table([{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }]);

// Error Boundaries (Vue)
new Vue({
  errorCaptured(err, vm, info) {
    console.error('Error:', err);
    return false; // Prevent propagation
  }
});