Tiny Frontend Logo
Quizes 1004

On This Page

What is JSON and its common operations?


What is JSON?

JSON is a text-based format that represents data as key-value pairs or arrays. It is a lightweight alternative to XML and is more human-readable than other formats like CSV (Comma Separated Values). JSON data is typically represented as a collection of name-value pairs, where each pair consists of a string key and a value.

Example of a Simple JSON Object

{
  "name": "John Doe",
  "age": 30,
  " occupation": "Software Developer"
}

Parsing JSON Strings

We can parse a JSON string into a JavaScript object using JSON.parse().

const jsonString = '{"name":"John Doe","age":30}';
const person = JSON.parse(jsonString);
console.log(person);
// Output: { name: "John Doe", age: 30 }

Stringifying JSON Objects

We can convert a JavaScript object to a JSON string using JSON.stringify().

const person = {
  name: 'Jane Doe',
  age: 25
};
const jsonString = JSON.stringify(person);
console.log(jsonString); // '{"name":"Jane Doe","age":25}'

Read Next

What is the difference between call(), apply() and bind()?


In JavaScript, call, apply, and bind are three methods that allow us to manipulate function behavior and pass arguments to functions. While they seem similar, each has its own unique use cases and usage scenarios.

How do you encode or decode a URL in JavaScript?


As a web developer, working with URLs is essential for building dynamic web applications that interact with APIs, handle redirects, and more. In this response, we'll discuss how to encode and decode URLs using JavaScript.

What is the main difference between localStorage and sessionStorage?


When it comes to storing data in web storage, two popular options are localStorage and sessionStorage. While both provide a way to store data locally on the client-side, there are key differences between them that make one more suitable for certain use cases than the other.

What is the main difference between localStorage and sessionStorage?


When it comes to storing data in web storage, two popular options are localStorage and sessionStorage. While both provide a way to store data locally on the client-side, there are key differences between them that make one more suitable for certain use cases than the other.

What is the purpose of the Array.slice() method?


The Array.prototype.slice() method allows you to create a shallow copy of a portion of an array, while preserving the original data. In other words, it extracts a subset of elements from an existing array and returns a new array with the desired data.

Syntax

Array.slice(startIndex, [endIndex]);

What is the difference between call(), apply() and bind()?


In JavaScript, call, apply, and bind are three methods that allow us to manipulate function behavior and pass arguments to functions. While they seem similar, each has its own unique use cases and usage scenarios.