chunk_id stringlengths 36 36 | source stringclasses 35
values | source_url stringlengths 0 290 | upstream_license stringclasses 1
value | document_id stringlengths 36 36 | chunk_index int64 0 324k | retrieved_at stringclasses 2
values | chunker_version stringclasses 4
values | content_hash stringlengths 15 64 | content stringlengths 50 44.7k | namespace stringclasses 9
values | source_name stringclasses 35
values | raw_text stringlengths 50 44.7k | cleaned_text stringlengths 50 44.7k | tags stringclasses 49
values | collection_name stringclasses 11
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
b1134ffc-b697-49b2-9b51-c6f5196a9072 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/data-structures-doubly-linked-list.md | unknown | 1b901c12-e1c5-49d5-bde9-169c907b5721 | 4 | SemanticChunker@1.0.0 | 8e3d947b47d2c003ea50e13db34b03e5a337775bbe248cdc4507a2c2290e55c4 | [Definition > Implementation]
```js
const list = new DoublyLinkedList();
list.insertFirst(1);
list.insertFirst(2);
list.insertFirst(3);
list.insertLast(4);
list.insertAt(3, 5);
list.size; // 5
list.head.value; // 3
list.head.next.value; // 2
list.tail.value; // 4
list.tail.previous.value; // 5
[...list.map(e => e.va... | unknown | unknown | [Definition > Implementation]
```js
const list = new DoublyLinkedList();
list.insertFirst(1);
list.insertFirst(2);
list.insertFirst(3);
list.insertLast(4);
list.insertAt(3, 5);
list.size; // 5
list.head.value; // 3
list.head.next.value; // 2
list.tail.value; // 4
list.tail.previous.value; // 5
[...list.map(e => e.va... | [Definition > Implementation]
```js
const list = new DoublyLinkedList();
list.insertFirst(1);
list.insertFirst(2);
list.insertFirst(3);
list.insertLast(4);
list.insertAt(3, 5);
list.size; // 5
list.head.value; // 3
list.head.next.value; // 2
list.tail.value; // 4
list.tail.previous.value; // 5
[...list.map(e => e.va... | code_snippets | ||
b4f6239d-94bf-49e3-a6a7-9454f224ede7 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/data-structures-doubly-linked-list.md | unknown | 1b901c12-e1c5-49d5-bde9-169c907b5721 | 1 | SemanticChunker@1.0.0 | 8b997f28897dcc1a1894a5ea394da263dacfdfd3fbe268d13c9fb1b8d53f27e7 | [Definition]
## Definition
A doubly linked list is a linear data structure that represents a collection of elements, where each element points both to the next and the previous one. The first element in the doubly linked list is the head and the last element is the tail.
![JavaScript Doubly Linked List visualization... | unknown | unknown | [Definition]
## Definition
A doubly linked list is a linear data structure that represents a collection of elements, where each element points both to the next and the previous one. The first element in the doubly linked list is the head and the last element is the tail.
![JavaScript Doubly Linked List visualization... | [Definition]
## Definition
A doubly linked list is a linear data structure that represents a collection of elements, where each element points both to the next and the previous one. The first element in the doubly linked list is the head and the last element is the tail.
![JavaScript Doubly Linked List visualization... | code_snippets | ||
3c551d8b-6933-470c-8396-58c4cafccdb1 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/data-structures-queue.md | unknown | 33186ccd-af2c-4c49-b22f-3ddd6786bb19 | 0 | SemanticChunker@1.0.0 | 25a6e8916fc7c1944196f684ff9c615d87b6f51d7f21e2d27b0f5f86e8a98894 | ---
title: JavaScript Data Structures - Queue
shortTitle: Queue
language: javascript
tags: [class]
cover: purple-flower-macro-2
excerpt: A queue is a linear data structure which follows a first in, first out (FIFO) order of operations.
listed: true
dateModified: 2021-07-29
--- | unknown | unknown | ---
title: JavaScript Data Structures - Queue
shortTitle: Queue
language: javascript
tags: [class]
cover: purple-flower-macro-2
excerpt: A queue is a linear data structure which follows a first in, first out (FIFO) order of operations.
listed: true
dateModified: 2021-07-29
--- | ---
title: JavaScript Data Structures - Queue
shortTitle: Queue
language: javascript
tags: [class]
cover: purple-flower-macro-2
excerpt: A queue is a linear data structure which follows a first in, first out (FIFO) order of operations.
listed: true
dateModified: 2021-07-29
--- | code_snippets | ||
c432f415-e2b6-453b-a2fa-47f6c49b1862 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/data-structures-queue.md | unknown | 33186ccd-af2c-4c49-b22f-3ddd6786bb19 | 1 | SemanticChunker@1.0.0 | 087406c61532257d79825147fccda8e29ada0510e2beb14f386480860828e255 | [Definition]
## Definition
A queue is a linear data structure that behaves like a real-world queue. It follows a first in, first out (FIFO) order of operations, similar to its real-world counterpart. This means that new items are added to the end of the queue, whereas items are removed from the start of the queue.
!... | unknown | unknown | [Definition]
## Definition
A queue is a linear data structure that behaves like a real-world queue. It follows a first in, first out (FIFO) order of operations, similar to its real-world counterpart. This means that new items are added to the end of the queue, whereas items are removed from the start of the queue.
!... | [Definition]
## Definition
A queue is a linear data structure that behaves like a real-world queue. It follows a first in, first out (FIFO) order of operations, similar to its real-world counterpart. This means that new items are added to the end of the queue, whereas items are removed from the start of the queue.
!... | code_snippets | ||
f34bccdb-cc88-497a-bf9f-4839a1f690ef | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/data-structures-queue.md | unknown | 33186ccd-af2c-4c49-b22f-3ddd6786bb19 | 2 | SemanticChunker@1.0.0 | 5ceb73251a521b7be971f35ba0ba87ce388c5dd510e1b2549483402c17c96830 | [Definition > Implementation]
## Implementation
```js
class Queue {
constructor() {
this.items = [];
}
enqueue(item) {
this.items.push(item);
}
dequeue() {
return this.items.shift();
}
peek() {
return this.items[0];
}
isEmpty() {
return this.items.length === 0;
}
}
```
- Create a `class` with a `c... | unknown | unknown | [Definition > Implementation]
## Implementation
```js
class Queue {
constructor() {
this.items = [];
}
enqueue(item) {
this.items.push(item);
}
dequeue() {
return this.items.shift();
}
peek() {
return this.items[0];
}
isEmpty() {
return this.items.length === 0;
}
}
```
- Create a `class` with a `c... | [Definition > Implementation]
## Implementation
```js
class Queue {
constructor() {
this.items = [];
}
enqueue(item) {
this.items.push(item);
}
dequeue() {
return this.items.shift();
}
peek() {
return this.items[0];
}
isEmpty() {
return this.items.length === 0;
}
}
```
- Create a `class` with a `c... | code_snippets | ||
0d3d39ee-8fb6-4efb-beec-da1b4cbb810e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/data-structures-binary-tree.md | unknown | 9e5b51d1-dd66-4a32-a48b-cf3ec83393b1 | 2 | SemanticChunker@1.0.0 | 3026334937d471c3be9ec6a832b60a9e4f1a0df6372d1f68c0f6675b1d9aa4b6 | [Definition > Implementation]
## Implementation
```js
class BinaryTreeNode {
constructor(key, value = key, parent = null) {
this.key = key;
this.value = value;
this.parent = parent;
this.left = null;
this.right = null;
}
get isLeaf() {
return this.left === null && this.right === null;
}
get hasChildren()... | unknown | unknown | [Definition > Implementation]
## Implementation
```js
class BinaryTreeNode {
constructor(key, value = key, parent = null) {
this.key = key;
this.value = value;
this.parent = parent;
this.left = null;
this.right = null;
}
get isLeaf() {
return this.left === null && this.right === null;
}
get hasChildren()... | [Definition > Implementation]
## Implementation
```js
class BinaryTreeNode {
constructor(key, value = key, parent = null) {
this.key = key;
this.value = value;
this.parent = parent;
this.left = null;
this.right = null;
}
get isLeaf() {
return this.left === null && this.right === null;
}
get hasChildren()... | code_snippets | ||
3b4e2311-5acf-42ab-b7f2-5f7084da5ccd | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/data-structures-binary-tree.md | unknown | 9e5b51d1-dd66-4a32-a48b-cf3ec83393b1 | 5 | SemanticChunker@1.0.0 | 9376cf32a7a6b444e3b91d03d70bb06abaff48b392c6f6751e78773da99be7ff | [Definition > Implementation]
```js
const tree = new BinaryTree(1, 'AB');
tree.insert(1, 11, 'AC');
tree.insert(1, 12, 'BC');
tree.insert(12, 121, 'BG', { right: true });
[...tree.preOrderTraversal()].map(x => x.value);
// ['AB', 'AC', 'BC', 'BCG']
[...tree.inOrderTraversal()].map(x => x.value);
// ['AC', 'AB', 'BC... | unknown | unknown | [Definition > Implementation]
```js
const tree = new BinaryTree(1, 'AB');
tree.insert(1, 11, 'AC');
tree.insert(1, 12, 'BC');
tree.insert(12, 121, 'BG', { right: true });
[...tree.preOrderTraversal()].map(x => x.value);
// ['AB', 'AC', 'BC', 'BCG']
[...tree.inOrderTraversal()].map(x => x.value);
// ['AC', 'AB', 'BC... | [Definition > Implementation]
```js
const tree = new BinaryTree(1, 'AB');
tree.insert(1, 11, 'AC');
tree.insert(1, 12, 'BC');
tree.insert(12, 121, 'BG', { right: true });
[...tree.preOrderTraversal()].map(x => x.value);
// ['AB', 'AC', 'BC', 'BCG']
[...tree.inOrderTraversal()].map(x => x.value);
// ['AC', 'AB', 'BC... | code_snippets | ||
715a3b20-f551-4166-a197-338c5d64bd0f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/data-structures-binary-tree.md | unknown | 9e5b51d1-dd66-4a32-a48b-cf3ec83393b1 | 0 | SemanticChunker@1.0.0 | e736bc7f477fd6b6db31febb723e741f6e4e481abaf31f828a0c9a195f274331 | ---
title: JavaScript Data Structures - Binary Tree
shortTitle: Binary Tree
language: javascript
tags: [class]
cover: purple-flower-macro-3
excerpt: A binary tree is a hierarchical data structure of linked nodes with at most two children each.
listed: true
dateModified: 2021-08-26
--- | unknown | unknown | ---
title: JavaScript Data Structures - Binary Tree
shortTitle: Binary Tree
language: javascript
tags: [class]
cover: purple-flower-macro-3
excerpt: A binary tree is a hierarchical data structure of linked nodes with at most two children each.
listed: true
dateModified: 2021-08-26
--- | ---
title: JavaScript Data Structures - Binary Tree
shortTitle: Binary Tree
language: javascript
tags: [class]
cover: purple-flower-macro-3
excerpt: A binary tree is a hierarchical data structure of linked nodes with at most two children each.
listed: true
dateModified: 2021-08-26
--- | code_snippets | ||
95a6b24d-c1f0-45bd-b13b-dd61b0eef086 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/data-structures-binary-tree.md | unknown | 9e5b51d1-dd66-4a32-a48b-cf3ec83393b1 | 3 | SemanticChunker@1.0.0 | ee2bdba893cf1787aecf1dc6b545f3e97cbd208e5be886dfe8ef034a59500ea9 | [Definition > Implementation]
```js
// [continued: part 1]
class BinaryTree {
constructor(key, value = key) {
this.root = new BinaryTreeNode(key, value);
}
*inOrderTraversal(node = this.root) {
if (node.left) yield* this.inOrderTraversal(node.left);
yield node;
if (node.right) yield* this.inOrderTraversal(node... | unknown | unknown | [Definition > Implementation]
```js
// [continued: part 1]
class BinaryTree {
constructor(key, value = key) {
this.root = new BinaryTreeNode(key, value);
}
*inOrderTraversal(node = this.root) {
if (node.left) yield* this.inOrderTraversal(node.left);
yield node;
if (node.right) yield* this.inOrderTraversal(node... | [Definition > Implementation]
```js
// [continued: part 1]
class BinaryTree {
constructor(key, value = key) {
this.root = new BinaryTreeNode(key, value);
}
*inOrderTraversal(node = this.root) {
if (node.left) yield* this.inOrderTraversal(node.left);
yield node;
if (node.right) yield* this.inOrderTraversal(node... | code_snippets | ||
9e68a5fd-c6cf-497d-a4d0-cd08cbbdd6a3 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/data-structures-binary-tree.md | unknown | 9e5b51d1-dd66-4a32-a48b-cf3ec83393b1 | 1 | SemanticChunker@1.0.0 | 1b1ad1b37ccd546e8fc7108166a9e382714af4e52c1b8e0f501a26fe33046b1d | [Definition]
## Definition
A binary tree is a data structure consisting of a set of linked nodes that represent a hierarchical tree structure. Each node is linked to others via parent-children relationship. Any given node can have at most two children (left and right). The first node in the binary tree is the root, w... | unknown | unknown | [Definition]
## Definition
A binary tree is a data structure consisting of a set of linked nodes that represent a hierarchical tree structure. Each node is linked to others via parent-children relationship. Any given node can have at most two children (left and right). The first node in the binary tree is the root, w... | [Definition]
## Definition
A binary tree is a data structure consisting of a set of linked nodes that represent a hierarchical tree structure. Each node is linked to others via parent-children relationship. Any given node can have at most two children (left and right). The first node in the binary tree is the root, w... | code_snippets | ||
fd4dcd58-76a8-480c-bd04-1307added942 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/data-structures-binary-tree.md | unknown | 9e5b51d1-dd66-4a32-a48b-cf3ec83393b1 | 4 | SemanticChunker@1.0.0 | 9745ffc03f7f8278e2e4412907da56f107b05eafb7ba3101bbd831a8bde8b26e | [Definition > Implementation]
- Create a `class` for the `BinaryTreeNode` with a `constructor` that initializes the appropriate `key`, `value`, `parent`, `left` and `right` properties.
- Define an `isLeaf` getter, that uses `Array.prototype.length` to check if both `left` and `right` are empty.
- Define a `hasChildren... | unknown | unknown | [Definition > Implementation]
- Create a `class` for the `BinaryTreeNode` with a `constructor` that initializes the appropriate `key`, `value`, `parent`, `left` and `right` properties.
- Define an `isLeaf` getter, that uses `Array.prototype.length` to check if both `left` and `right` are empty.
- Define a `hasChildren... | [Definition > Implementation]
- Create a `class` for the `BinaryTreeNode` with a `constructor` that initializes the appropriate `key`, `value`, `parent`, `left` and `right` properties.
- Define an `isLeaf` getter, that uses `Array.prototype.length` to check if both `left` and `right` are empty.
- Define a `hasChildren... | code_snippets | ||
3121170d-a608-4732-9bc8-82448773f722 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/date-inside-business-hours.md | unknown | c8b64597-bfee-4b99-b551-60ada12aa26c | 3 | SemanticChunker@1.0.0 | 3710f13e0a2d0f64be2413db0a6291dd3d1eb74983eb65beff9e56815fae3c61 | [Using the `Date` object > Using `Intl.DateTimeFormat` for specific timezones]
```js
const holidays = [
[1, 1], // New Year's Day
[6, 1], // Epiphany
[25, 3], // Greek Independence Day
[1, 5], // Labour Day
[15, 8], // Dormition of the Holy Virgin
[28, 10], // Ochi Day
[25, 12], // Christmas Day
[26, 12] // Bo... | unknown | unknown | [Using the `Date` object > Using `Intl.DateTimeFormat` for specific timezones]
```js
const holidays = [
[1, 1], // New Year's Day
[6, 1], // Epiphany
[25, 3], // Greek Independence Day
[1, 5], // Labour Day
[15, 8], // Dormition of the Holy Virgin
[28, 10], // Ochi Day
[25, 12], // Christmas Day
[26, 12] // Bo... | [Using the `Date` object > Using `Intl.DateTimeFormat` for specific timezones]
```js
const holidays = [
[1, 1], // New Year's Day
[6, 1], // Epiphany
[25, 3], // Greek Independence Day
[1, 5], // Labour Day
[15, 8], // Dormition of the Holy Virgin
[28, 10], // Ochi Day
[25, 12], // Christmas Day
[26, 12] // Bo... | code_snippets | ||
b336a84f-80fd-4080-80a1-a179af0085df | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/date-inside-business-hours.md | unknown | c8b64597-bfee-4b99-b551-60ada12aa26c | 1 | SemanticChunker@1.0.0 | b632751c2c1947968e74a298b370a83d034f1a50ffb0cb901ebd1d82f47b52b4 | [Using the `Date` object]
## Using the `Date` object
The `Date` object in JavaScript provides a number of methods to work with dates and times. We can use `Date.prototype.getDay()` and `Date.prototype.getHours()` methods to get the **day of the week** and the **hour of the day**, respectively.
Then, we can use a sim... | unknown | unknown | [Using the `Date` object]
## Using the `Date` object
The `Date` object in JavaScript provides a number of methods to work with dates and times. We can use `Date.prototype.getDay()` and `Date.prototype.getHours()` methods to get the **day of the week** and the **hour of the day**, respectively.
Then, we can use a sim... | [Using the `Date` object]
## Using the `Date` object
The `Date` object in JavaScript provides a number of methods to work with dates and times. We can use `Date.prototype.getDay()` and `Date.prototype.getHours()` methods to get the **day of the week** and the **hour of the day**, respectively.
Then, we can use a sim... | code_snippets | ||
be965a70-3ca9-4682-a6dc-2fefaf47292b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/date-inside-business-hours.md | unknown | c8b64597-bfee-4b99-b551-60ada12aa26c | 2 | SemanticChunker@1.0.0 | 439910f2a1a4087f40905aa5d5abb5f485c54b06538413e17c56599195a2e6ed | [Using the `Date` object > Using `Intl.DateTimeFormat` for specific timezones]
## Using `Intl.DateTimeFormat` for specific timezones
Depending on where you are in the world and if your users are on the same timezone, you might want to get the time for a **specific timezone**. This is significantly more involved, but ... | unknown | unknown | [Using the `Date` object > Using `Intl.DateTimeFormat` for specific timezones]
## Using `Intl.DateTimeFormat` for specific timezones
Depending on where you are in the world and if your users are on the same timezone, you might want to get the time for a **specific timezone**. This is significantly more involved, but ... | [Using the `Date` object > Using `Intl.DateTimeFormat` for specific timezones]
## Using `Intl.DateTimeFormat` for specific timezones
Depending on where you are in the world and if your users are on the same timezone, you might want to get the time for a **specific timezone**. This is significantly more involved, but ... | code_snippets | ||
f223f62c-5780-4f91-8887-fb8a81de9c97 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/date-inside-business-hours.md | unknown | c8b64597-bfee-4b99-b551-60ada12aa26c | 0 | SemanticChunker@1.0.0 | ad2774bf41d0e9610ed68266d340ebcba6967792ce9dc28047140a008513ef2f | ---
title: Check if a JavaScript date is inside business hours
shortTitle: Date inside business hours
language: javascript
tags: [date]
cover: shelf-plant
excerpt: Leverage the `Date` object to check if a given date is inside business hours.
listed: true
dateModified: 2024-03-13
---
Checking if a given date is inside ... | unknown | unknown | ---
title: Check if a JavaScript date is inside business hours
shortTitle: Date inside business hours
language: javascript
tags: [date]
cover: shelf-plant
excerpt: Leverage the `Date` object to check if a given date is inside business hours.
listed: true
dateModified: 2024-03-13
---
Checking if a given date is inside ... | ---
title: Check if a JavaScript date is inside business hours
shortTitle: Date inside business hours
language: javascript
tags: [date]
cover: shelf-plant
excerpt: Leverage the `Date` object to check if a given date is inside business hours.
listed: true
dateModified: 2024-03-13
---
Checking if a given date is inside ... | code_snippets | ||
8471b54e-a48f-4deb-b0e6-2781ce0402c0 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/data-structures-tree.md | unknown | 4b575008-59f8-4968-a553-a3f416326365 | 2 | SemanticChunker@1.0.0 | 4cd3be7de204ff2deaa5b501aabd6db46bf77fbd12e116d5c8e9aafa4ecdb110 | [Definition > Implementation]
## Implementation
```js
class TreeNode {
constructor(key, value = key, parent = null) {
this.key = key;
this.value = value;
this.parent = parent;
this.children = [];
}
get isLeaf() {
return this.children.length === 0;
}
get hasChildren() {
return !this.isLeaf;
}
}
class Tr... | unknown | unknown | [Definition > Implementation]
## Implementation
```js
class TreeNode {
constructor(key, value = key, parent = null) {
this.key = key;
this.value = value;
this.parent = parent;
this.children = [];
}
get isLeaf() {
return this.children.length === 0;
}
get hasChildren() {
return !this.isLeaf;
}
}
class Tr... | [Definition > Implementation]
## Implementation
```js
class TreeNode {
constructor(key, value = key, parent = null) {
this.key = key;
this.value = value;
this.parent = parent;
this.children = [];
}
get isLeaf() {
return this.children.length === 0;
}
get hasChildren() {
return !this.isLeaf;
}
}
class Tr... | code_snippets | ||
8645a872-f927-4043-98a3-bb2d25db3464 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/data-structures-tree.md | unknown | 4b575008-59f8-4968-a553-a3f416326365 | 3 | SemanticChunker@1.0.0 | b9885fad4de7cc76539a0e518fef5b1380562ff869426385e26f35e6406522db | [Definition > Implementation]
- Create a `class` for the `TreeNode` with a `constructor` that initializes the appropriate `key`, `value`, `parent` and `children` properties.
- Define an `isLeaf` getter, that uses `Array.prototype.length` to check if `children` is empty.
- Define a `hasChildren` getter, that is the rev... | unknown | unknown | [Definition > Implementation]
- Create a `class` for the `TreeNode` with a `constructor` that initializes the appropriate `key`, `value`, `parent` and `children` properties.
- Define an `isLeaf` getter, that uses `Array.prototype.length` to check if `children` is empty.
- Define a `hasChildren` getter, that is the rev... | [Definition > Implementation]
- Create a `class` for the `TreeNode` with a `constructor` that initializes the appropriate `key`, `value`, `parent` and `children` properties.
- Define an `isLeaf` getter, that uses `Array.prototype.length` to check if `children` is empty.
- Define a `hasChildren` getter, that is the rev... | code_snippets | ||
904904e4-6274-4318-8d1e-f69cf3bff3aa | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/data-structures-tree.md | unknown | 4b575008-59f8-4968-a553-a3f416326365 | 0 | SemanticChunker@1.0.0 | a13e69c2f9ccd11140fd93338677181de1d21df2063d42d51ff4e0e47300b5f9 | ---
title: JavaScript Data Structures - Tree
shortTitle: Tree
language: javascript
tags: [class]
cover: purple-flower-macro-2
excerpt: A tree is a data structure consisting of a set of linked nodes representing a hierarchical tree structure.
listed: true
dateModified: 2021-08-22
--- | unknown | unknown | ---
title: JavaScript Data Structures - Tree
shortTitle: Tree
language: javascript
tags: [class]
cover: purple-flower-macro-2
excerpt: A tree is a data structure consisting of a set of linked nodes representing a hierarchical tree structure.
listed: true
dateModified: 2021-08-22
--- | ---
title: JavaScript Data Structures - Tree
shortTitle: Tree
language: javascript
tags: [class]
cover: purple-flower-macro-2
excerpt: A tree is a data structure consisting of a set of linked nodes representing a hierarchical tree structure.
listed: true
dateModified: 2021-08-22
--- | code_snippets | ||
c958daa0-7f74-486d-9d59-fa8ac197d658 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/data-structures-tree.md | unknown | 4b575008-59f8-4968-a553-a3f416326365 | 1 | SemanticChunker@1.0.0 | e1126e38a929e9340c619972a48bfef8bd07424142858077a6153bcbe03e18a1 | [Definition]
## Definition
A tree is a data structure consisting of a set of linked nodes that represent a hierarchical tree structure. Each node is linked to others via parent-children relationship. The first node in the tree is the root, whereas nodes without any children are the leaves.
![JavaScript Tree visualiz... | unknown | unknown | [Definition]
## Definition
A tree is a data structure consisting of a set of linked nodes that represent a hierarchical tree structure. Each node is linked to others via parent-children relationship. The first node in the tree is the root, whereas nodes without any children are the leaves.
![JavaScript Tree visualiz... | [Definition]
## Definition
A tree is a data structure consisting of a set of linked nodes that represent a hierarchical tree structure. Each node is linked to others via parent-children relationship. The first node in the tree is the root, whereas nodes without any children are the leaves.
![JavaScript Tree visualiz... | code_snippets | ||
4354c4de-8514-46e4-825d-b5b02111f0eb | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/data-structures-stack.md | unknown | c3e5620d-81f4-41d3-ad40-21b668cceab1 | 1 | SemanticChunker@1.0.0 | ed1570ebcb7dd373137d04e6727ee93415591b4b799c205e14a531d1e270755b | [Definition]
## Definition
A stack is a linear data structure that behaves like a real-world stack of items. It follows a last in, first out (LIFO) order of operations, similar to its real-world counterpart. This means that new items are added to the top of the stack and items are removed from the top of the stack as... | unknown | unknown | [Definition]
## Definition
A stack is a linear data structure that behaves like a real-world stack of items. It follows a last in, first out (LIFO) order of operations, similar to its real-world counterpart. This means that new items are added to the top of the stack and items are removed from the top of the stack as... | [Definition]
## Definition
A stack is a linear data structure that behaves like a real-world stack of items. It follows a last in, first out (LIFO) order of operations, similar to its real-world counterpart. This means that new items are added to the top of the stack and items are removed from the top of the stack as... | code_snippets | ||
96f0feb8-0511-478a-ac3b-e12e723df687 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/data-structures-stack.md | unknown | c3e5620d-81f4-41d3-ad40-21b668cceab1 | 0 | SemanticChunker@1.0.0 | 61ea7976f5ef0f13397445f89c0a77918448fe5bc0931d9fe95a0d620854164f | ---
title: JavaScript Data Structures - Stack
shortTitle: Stack
language: javascript
tags: [class]
cover: purple-flower-macro-1
excerpt: A stack is a linear data structure which follows a last in, first out (LIFO) order of operations.
listed: true
dateModified: 2021-08-03
--- | unknown | unknown | ---
title: JavaScript Data Structures - Stack
shortTitle: Stack
language: javascript
tags: [class]
cover: purple-flower-macro-1
excerpt: A stack is a linear data structure which follows a last in, first out (LIFO) order of operations.
listed: true
dateModified: 2021-08-03
--- | ---
title: JavaScript Data Structures - Stack
shortTitle: Stack
language: javascript
tags: [class]
cover: purple-flower-macro-1
excerpt: A stack is a linear data structure which follows a last in, first out (LIFO) order of operations.
listed: true
dateModified: 2021-08-03
--- | code_snippets | ||
d2834169-283c-4baf-a74a-c67b3365507f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/data-structures-stack.md | unknown | c3e5620d-81f4-41d3-ad40-21b668cceab1 | 2 | SemanticChunker@1.0.0 | f6e911ff18ae6e4cf89b3fdc0ad3aaf5a1ec59337989e64f405bae1eea850f62 | [Definition > Implementation]
## Implementation
```js
class Stack {
constructor() {
this.items = [];
}
push(item) {
this.items.unshift(item);
}
pop(item) {
return this.items.shift();
}
peek(item) {
return this.items[0];
}
isEmpty() {
return this.items.length === 0;
}
}
```
- Create a `class` with ... | unknown | unknown | [Definition > Implementation]
## Implementation
```js
class Stack {
constructor() {
this.items = [];
}
push(item) {
this.items.unshift(item);
}
pop(item) {
return this.items.shift();
}
peek(item) {
return this.items[0];
}
isEmpty() {
return this.items.length === 0;
}
}
```
- Create a `class` with ... | [Definition > Implementation]
## Implementation
```js
class Stack {
constructor() {
this.items = [];
}
push(item) {
this.items.unshift(item);
}
pop(item) {
return this.items.shift();
}
peek(item) {
return this.items[0];
}
isEmpty() {
return this.items.length === 0;
}
}
```
- Create a `class` with ... | code_snippets | ||
20ae29c4-d228-4d40-959d-8815cb1f0293 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/day-week-month-quarter-of-year.md | unknown | bd2515e9-b427-4d2f-81bd-50f3abb2d597 | 2 | SemanticChunker@1.0.0 | 11d08e7af0e276ec458834d8764d0b2c36484a7365000458cdc72dfad2f5e87f | [Day of year > Week of year]
### Week of year
Calculating the week of the year also starts by calculating the first day of the year as a `Date` object. We can then use `Date.prototype.setDate()`, `Date.prototype.getDate()` and `Date.prototype.getDay()` along with the modulo (`%`) operator to get the first Monday of t... | unknown | unknown | [Day of year > Week of year]
### Week of year
Calculating the week of the year also starts by calculating the first day of the year as a `Date` object. We can then use `Date.prototype.setDate()`, `Date.prototype.getDate()` and `Date.prototype.getDay()` along with the modulo (`%`) operator to get the first Monday of t... | [Day of year > Week of year]
### Week of year
Calculating the week of the year also starts by calculating the first day of the year as a `Date` object. We can then use `Date.prototype.setDate()`, `Date.prototype.getDate()` and `Date.prototype.getDay()` along with the modulo (`%`) operator to get the first Monday of t... | code_snippets | ||
af21a507-867f-4682-bffd-41c0ef5b0699 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/day-week-month-quarter-of-year.md | unknown | bd2515e9-b427-4d2f-81bd-50f3abb2d597 | 1 | SemanticChunker@1.0.0 | 8f2e1c4a7a33c00863ee61d9a2daf2db109227319900212883e9bd794d660394 | [Day of year]
## Day of year
Finding the day of the year (in the range `1-366`) from a `Date` object is fairly straightforward. We can use the `Date` constructor and `Date.prototype.getFullYear()` to get the **first day of the year** as a `Date` object.
Then, we can subtract the first day of the year from the given ... | unknown | unknown | [Day of year]
## Day of year
Finding the day of the year (in the range `1-366`) from a `Date` object is fairly straightforward. We can use the `Date` constructor and `Date.prototype.getFullYear()` to get the **first day of the year** as a `Date` object.
Then, we can subtract the first day of the year from the given ... | [Day of year]
## Day of year
Finding the day of the year (in the range `1-366`) from a `Date` object is fairly straightforward. We can use the `Date` constructor and `Date.prototype.getFullYear()` to get the **first day of the year** as a `Date` object.
Then, we can subtract the first day of the year from the given ... | code_snippets | ||
c4eaeaf4-664c-4f40-8e0d-2ad182fdbdd0 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/day-week-month-quarter-of-year.md | unknown | bd2515e9-b427-4d2f-81bd-50f3abb2d597 | 3 | SemanticChunker@1.0.0 | a7327e0b933f5614424b65269ac67ff8e04d78bb693e6ca0ecb285b89db1fc5c | [Week of year > Month of year]
### Month of year
Finding the month of the year (in the range `1-12`) from a `Date` object is the most straightforward of the bunch. Simply use `Date.prototype.getMonth()` to get the current month in the range `0-11` and add `1` to map it to the range `1-12`.
```js
const monthOfYear = ... | unknown | unknown | [Week of year > Month of year]
### Month of year
Finding the month of the year (in the range `1-12`) from a `Date` object is the most straightforward of the bunch. Simply use `Date.prototype.getMonth()` to get the current month in the range `0-11` and add `1` to map it to the range `1-12`.
```js
const monthOfYear = ... | [Week of year > Month of year]
### Month of year
Finding the month of the year (in the range `1-12`) from a `Date` object is the most straightforward of the bunch. Simply use `Date.prototype.getMonth()` to get the current month in the range `0-11` and add `1` to map it to the range `1-12`.
```js
const monthOfYear = ... | code_snippets | ||
c98595d9-b815-4c76-b965-9a3efa649a9b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/day-week-month-quarter-of-year.md | unknown | bd2515e9-b427-4d2f-81bd-50f3abb2d597 | 0 | SemanticChunker@1.0.0 | de68602ee9c66e8cc29945eb1992bb77db219aa894b3ac201a2d805c7569f0bb | ---
title: Find the day, week, month, or quarter of the year using JavaScript
shortTitle: Day, week, month, or quarter of year
language: javascript
tags: [date]
cover: godray-computer-mug
excerpt: Determine the day, week, month, or quarter of the year that a date corresponds to, using vanilla JavaScript.
listed: true
d... | unknown | unknown | ---
title: Find the day, week, month, or quarter of the year using JavaScript
shortTitle: Day, week, month, or quarter of year
language: javascript
tags: [date]
cover: godray-computer-mug
excerpt: Determine the day, week, month, or quarter of the year that a date corresponds to, using vanilla JavaScript.
listed: true
d... | ---
title: Find the day, week, month, or quarter of the year using JavaScript
shortTitle: Day, week, month, or quarter of year
language: javascript
tags: [date]
cover: godray-computer-mug
excerpt: Determine the day, week, month, or quarter of the year that a date corresponds to, using vanilla JavaScript.
listed: true
d... | code_snippets | ||
cc652b4d-9d80-4a05-a80f-6092cdbb9f72 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/day-week-month-quarter-of-year.md | unknown | bd2515e9-b427-4d2f-81bd-50f3abb2d597 | 4 | SemanticChunker@1.0.0 | fcb13b20ce7a583ad241f464364598c77d205cf10b71112e1bf1010edbac31ee | [Week of year > Quarter of year]
### Quarter of year
Finding the quarter of the year (in the range `1-4`) from a `Date` is quite simple, too. After retrieving the current month, we can use `Math.ceil()` and divide the month by `3` to get the current quarter.
```js
const quarterOfYear = date => Math.ceil((date.getMon... | unknown | unknown | [Week of year > Quarter of year]
### Quarter of year
Finding the quarter of the year (in the range `1-4`) from a `Date` is quite simple, too. After retrieving the current month, we can use `Math.ceil()` and divide the month by `3` to get the current quarter.
```js
const quarterOfYear = date => Math.ceil((date.getMon... | [Week of year > Quarter of year]
### Quarter of year
Finding the quarter of the year (in the range `1-4`) from a `Date` is quite simple, too. After retrieving the current month, we can use `Math.ceil()` and divide the month by `3` to get the current quarter.
```js
const quarterOfYear = date => Math.ceil((date.getMon... | code_snippets | ||
663f441f-f9a8-4903-8d53-1f19009d6686 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/date-yesterday-today-tomorrow.md | unknown | 3b3842a3-6b03-4418-a36b-11d663a7052c | 0 | SemanticChunker@1.0.0 | 41ec64cb6d99f539404cb081cb1de67e0136946b1858463d931525f06cd2d8d9 | ---
title: Date of yesterday, today or tomorrow in JavaScript
shortTitle: Date of yesterday, today or tomorrow
language: javascript
tags: [date]
cover: travel-mug-2
excerpt: Easily calculate the date of yesterday, today or tomorrow in JavaScript.
listed: true
dateModified: 2024-01-06
---
In a previous post, we've cove... | unknown | unknown | ---
title: Date of yesterday, today or tomorrow in JavaScript
shortTitle: Date of yesterday, today or tomorrow
language: javascript
tags: [date]
cover: travel-mug-2
excerpt: Easily calculate the date of yesterday, today or tomorrow in JavaScript.
listed: true
dateModified: 2024-01-06
---
In a previous post, we've cove... | ---
title: Date of yesterday, today or tomorrow in JavaScript
shortTitle: Date of yesterday, today or tomorrow
language: javascript
tags: [date]
cover: travel-mug-2
excerpt: Easily calculate the date of yesterday, today or tomorrow in JavaScript.
listed: true
dateModified: 2024-01-06
---
In a previous post, we've cove... | code_snippets | ||
981adbeb-6c1c-4cb1-a711-ce1904a116c6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/date-yesterday-today-tomorrow.md | unknown | 3b3842a3-6b03-4418-a36b-11d663a7052c | 1 | SemanticChunker@1.0.0 | e85efec5c13c28fce744fa1da034aeb4c79332b1e1a767107d1508642b2b971e | [Date of today]
## Date of today
The current date is the easiest to calculate. We can simply use the `Date` constructor to get the current date.
```js
const today = () => new Date();
today().toISOString().split('T')[0];
// 2018-10-18 (if current date is 2018-10-18)
``` | unknown | unknown | [Date of today]
## Date of today
The current date is the easiest to calculate. We can simply use the `Date` constructor to get the current date.
```js
const today = () => new Date();
today().toISOString().split('T')[0];
// 2018-10-18 (if current date is 2018-10-18)
``` | [Date of today]
## Date of today
The current date is the easiest to calculate. We can simply use the `Date` constructor to get the current date.
```js
const today = () => new Date();
today().toISOString().split('T')[0];
// 2018-10-18 (if current date is 2018-10-18)
``` | code_snippets | ||
e9c7f420-09c2-4431-a946-7c5f97281e6b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/date-yesterday-today-tomorrow.md | unknown | 3b3842a3-6b03-4418-a36b-11d663a7052c | 3 | SemanticChunker@1.0.0 | 1890bea56729836121c8282a67eeae1019863f04497245ed0f4ec04fa2538e08 | [Date of today > Date of tomorrow]
## Date of tomorrow
To calculate the date of tomorrow, we simply need to **increment the current date by one**, instead of decrementing it.
```js
const tomorrow = () => {
let d = new Date();
d.setDate(d.getDate() + 1);
return d;
};
tomorrow().toISOString().split('T')[0];
// 201... | unknown | unknown | [Date of today > Date of tomorrow]
## Date of tomorrow
To calculate the date of tomorrow, we simply need to **increment the current date by one**, instead of decrementing it.
```js
const tomorrow = () => {
let d = new Date();
d.setDate(d.getDate() + 1);
return d;
};
tomorrow().toISOString().split('T')[0];
// 201... | [Date of today > Date of tomorrow]
## Date of tomorrow
To calculate the date of tomorrow, we simply need to **increment the current date by one**, instead of decrementing it.
```js
const tomorrow = () => {
let d = new Date();
d.setDate(d.getDate() + 1);
return d;
};
tomorrow().toISOString().split('T')[0];
// 201... | code_snippets | ||
f2772d67-1631-40ba-8bb0-f26818af5aee | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/date-yesterday-today-tomorrow.md | unknown | 3b3842a3-6b03-4418-a36b-11d663a7052c | 2 | SemanticChunker@1.0.0 | 9106fbaf2178240a086f3bab076f3d4291de6ad5adcbecfd95daf76ce6333deb | [Date of today > Date of yesterday]
## Date of yesterday
To calculate the date of yesterday, we simply need to **decrement the current date by one**. To do this, we will use `Date.prototype.getDate()` and `Date.prototype.setDate()` to get and set the date, respectively.
```js
const yesterday = () => {
let d = new D... | unknown | unknown | [Date of today > Date of yesterday]
## Date of yesterday
To calculate the date of yesterday, we simply need to **decrement the current date by one**. To do this, we will use `Date.prototype.getDate()` and `Date.prototype.setDate()` to get and set the date, respectively.
```js
const yesterday = () => {
let d = new D... | [Date of today > Date of yesterday]
## Date of yesterday
To calculate the date of yesterday, we simply need to **decrement the current date by one**. To do this, we will use `Date.prototype.getDate()` and `Date.prototype.setDate()` to get and set the date, respectively.
```js
const yesterday = () => {
let d = new D... | code_snippets | ||
ac22e1e1-079d-444e-9f23-512910638dc7 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/date-range-generator.md | unknown | b2835835-d9a8-4a44-ab04-9147b4dbc5fb | 0 | SemanticChunker@1.0.0 | 868df7430b8f5e295484ee635e11335c8ec221585582b37aa30aa5ac75678c6f | ---
title: Date range generator in JavaScript
shortTitle: Date range generator
language: javascript
tags: [date,function,generator]
cover: portal-timelapse
excerpt: Create a generator that generates all dates in a given range.
listed: true
dateModified: 2024-07-31
---
Generating a range of `Date` values is very common... | unknown | unknown | ---
title: Date range generator in JavaScript
shortTitle: Date range generator
language: javascript
tags: [date,function,generator]
cover: portal-timelapse
excerpt: Create a generator that generates all dates in a given range.
listed: true
dateModified: 2024-07-31
---
Generating a range of `Date` values is very common... | ---
title: Date range generator in JavaScript
shortTitle: Date range generator
language: javascript
tags: [date,function,generator]
cover: portal-timelapse
excerpt: Create a generator that generates all dates in a given range.
listed: true
dateModified: 2024-07-31
---
Generating a range of `Date` values is very common... | code_snippets | ||
77d18e87-be2f-4c36-bac4-7b6d10309177 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/debounce-promise.md | unknown | 3e9c925c-3d68-4125-b1a0-b130fedbcee3 | 1 | SemanticChunker@1.0.0 | e78f1fa68b0d60cd4c1a70ac82ba9ef2d75948e38ac2c8514e2f9c2ed9b374ca | ```js
const debouncePromise = (fn, ms = 0) => {
let timeoutId;
const pending = [];
return (...args) =>
new Promise((res, rej) => {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
const currentPending = [...pending];
pending.length = 0;
Promise.resolve(fn.apply(this, args)).then(
data => {
currentPend... | unknown | unknown | ```js
const debouncePromise = (fn, ms = 0) => {
let timeoutId;
const pending = [];
return (...args) =>
new Promise((res, rej) => {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
const currentPending = [...pending];
pending.length = 0;
Promise.resolve(fn.apply(this, args)).then(
data => {
currentPend... | ```js
const debouncePromise = (fn, ms = 0) => {
let timeoutId;
const pending = [];
return (...args) =>
new Promise((res, rej) => {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
const currentPending = [...pending];
pending.length = 0;
Promise.resolve(fn.apply(this, args)).then(
data => {
currentPend... | code_snippets | ||
aef83e5f-c2c0-4ec6-9efd-9dc61e4bbe35 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/debounce-promise.md | unknown | 3e9c925c-3d68-4125-b1a0-b130fedbcee3 | 0 | SemanticChunker@1.0.0 | e4a5f92ed604a8776b0987cfbbc589662737738adc1c0997d91c705e35708238 | ---
title: Debounce a JavaScript function and return a promise
shortTitle: Debounce promise
language: javascript
tags: [promises,function]
excerpt: Easily create a debounced function that returns a promise.
cover: chess-pawns
listed: true
dateModified: 2023-10-13
---
**Debouncing** is a technique used to **limit the n... | unknown | unknown | ---
title: Debounce a JavaScript function and return a promise
shortTitle: Debounce promise
language: javascript
tags: [promises,function]
excerpt: Easily create a debounced function that returns a promise.
cover: chess-pawns
listed: true
dateModified: 2023-10-13
---
**Debouncing** is a technique used to **limit the n... | ---
title: Debounce a JavaScript function and return a promise
shortTitle: Debounce promise
language: javascript
tags: [promises,function]
excerpt: Easily create a debounced function that returns a promise.
cover: chess-pawns
listed: true
dateModified: 2023-10-13
---
**Debouncing** is a technique used to **limit the n... | code_snippets | ||
8418a971-e6fb-4e55-bca5-9cf860ddf69a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/date-to-unix-timestamp.md | unknown | 40ee484f-fbb9-4472-b63c-491ba9cf3ab2 | 0 | SemanticChunker@1.0.0 | ea8475eddbf7efb98a2bfe59f24fb9d92352f62684ee802b4d62247729b8ad76 | ---
title: Convert between a JavaScript Date object and a Unix timestamp
shortTitle: Date to Unix timestamp
language: javascript
tags: [date]
cover: number-2
excerpt: Easily convert between a JavaScript Date object and a Unix timestamp.
listed: true
dateModified: 2024-01-07
---
Unix timestamps are a **number represent... | unknown | unknown | ---
title: Convert between a JavaScript Date object and a Unix timestamp
shortTitle: Date to Unix timestamp
language: javascript
tags: [date]
cover: number-2
excerpt: Easily convert between a JavaScript Date object and a Unix timestamp.
listed: true
dateModified: 2024-01-07
---
Unix timestamps are a **number represent... | ---
title: Convert between a JavaScript Date object and a Unix timestamp
shortTitle: Date to Unix timestamp
language: javascript
tags: [date]
cover: number-2
excerpt: Easily convert between a JavaScript Date object and a Unix timestamp.
listed: true
dateModified: 2024-01-07
---
Unix timestamps are a **number represent... | code_snippets | ||
1c93bd8e-e0cc-4de6-b1a7-348d21debf45 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/days-in-month.md | unknown | a9ddc271-edd2-4173-ba39-8083d8a709fd | 0 | SemanticChunker@1.0.0 | f7b5ff90a07ee0aec42d0fcda34c0775a998805e4d512e563397ded236cf3cc2 | ---
title: Find the number of days in a month using JavaScript
shortTitle: Number of days in month
language: javascript
tags: [date]
cover: laptop-plants-2
excerpt: Calculate the number of days in a month for a given year using JavaScript.
listed: true
dateModified: 2024-02-26
---
Working with dates is admittedly hard... | unknown | unknown | ---
title: Find the number of days in a month using JavaScript
shortTitle: Number of days in month
language: javascript
tags: [date]
cover: laptop-plants-2
excerpt: Calculate the number of days in a month for a given year using JavaScript.
listed: true
dateModified: 2024-02-26
---
Working with dates is admittedly hard... | ---
title: Find the number of days in a month using JavaScript
shortTitle: Number of days in month
language: javascript
tags: [date]
cover: laptop-plants-2
excerpt: Calculate the number of days in a month for a given year using JavaScript.
listed: true
dateModified: 2024-02-26
---
Working with dates is admittedly hard... | code_snippets | ||
df45ab36-18d5-433c-a651-0ac2531d4000 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/debounce-function.md | unknown | 89ab0dd8-33e8-4022-ae3b-19e4bb6bf545 | 0 | SemanticChunker@1.0.0 | 342db6486690eff96a7242ae5b7cd480f35d32fe9a1d858d2288a9e7a159bb8a | ---
title: Debounce a JavaScript function
shortTitle: Debounce function
language: javascript
tags: [function]
cover: solitude-beach
excerpt: Create a debounced function that waits a certain amount of time before invoking the provided function again.
listed: true
dateModified: 2023-10-12
---
**Debouncing** is a techniq... | unknown | unknown | ---
title: Debounce a JavaScript function
shortTitle: Debounce function
language: javascript
tags: [function]
cover: solitude-beach
excerpt: Create a debounced function that waits a certain amount of time before invoking the provided function again.
listed: true
dateModified: 2023-10-12
---
**Debouncing** is a techniq... | ---
title: Debounce a JavaScript function
shortTitle: Debounce function
language: javascript
tags: [function]
cover: solitude-beach
excerpt: Create a debounced function that waits a certain amount of time before invoking the provided function again.
listed: true
dateModified: 2023-10-12
---
**Debouncing** is a techniq... | code_snippets | ||
b25ca668-f8a2-4721-81c3-a119979c2141 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/decimal-to-hex.md | unknown | e22f87c1-fb7f-4a59-8e6e-211ddb7c4dcb | 0 | SemanticChunker@1.0.0 | bde88d088a14d65acd829b4c5132a55a18022b5f23b4b3ed64e812805d60b477 | ---
title: Convert decimal number to hexadecimal
shortTitle: Decimal to hexadecimal
language: javascript
tags: [number]
cover: waves-from-above
excerpt: Ever needed to convert a decimal number to hexadecimal? Here's a quick and easy way to do it.
listed: true
dateModified: 2022-09-21
---
Numeric values are represented... | unknown | unknown | ---
title: Convert decimal number to hexadecimal
shortTitle: Decimal to hexadecimal
language: javascript
tags: [number]
cover: waves-from-above
excerpt: Ever needed to convert a decimal number to hexadecimal? Here's a quick and easy way to do it.
listed: true
dateModified: 2022-09-21
---
Numeric values are represented... | ---
title: Convert decimal number to hexadecimal
shortTitle: Decimal to hexadecimal
language: javascript
tags: [number]
cover: waves-from-above
excerpt: Ever needed to convert a decimal number to hexadecimal? Here's a quick and easy way to do it.
listed: true
dateModified: 2022-09-21
---
Numeric values are represented... | code_snippets | ||
575107e2-7442-4935-968c-7d1789dd495d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/date-is-weekday-or-weekend.md | unknown | 17ac49f6-c338-4d90-9bf6-ac6757eff014 | 0 | SemanticChunker@1.0.0 | ac95466a2cea4c6c935eed876a34d9b05b42bc29edefda8d92ff83494fad1210 | ---
title: Determine if a JavaScript date is a weekday or weekend
shortTitle: Date is weekday or weekend
language: javascript
tags: [date]
cover: tropical-bike
excerpt: Quickly and easily determine if a given JavaScript `Date` object is a weekday or weekend.
listed: true
dateModified: 2024-01-06
---
I've often found m... | unknown | unknown | ---
title: Determine if a JavaScript date is a weekday or weekend
shortTitle: Date is weekday or weekend
language: javascript
tags: [date]
cover: tropical-bike
excerpt: Quickly and easily determine if a given JavaScript `Date` object is a weekday or weekend.
listed: true
dateModified: 2024-01-06
---
I've often found m... | ---
title: Determine if a JavaScript date is a weekday or weekend
shortTitle: Date is weekday or weekend
language: javascript
tags: [date]
cover: tropical-bike
excerpt: Quickly and easily determine if a given JavaScript `Date` object is a weekday or weekend.
listed: true
dateModified: 2024-01-06
---
I've often found m... | code_snippets | ||
e11427f1-a510-4de0-a0e1-fa0b62507a55 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/days-ago-days-from-today.md | unknown | a9f17735-8f73-407c-8cbf-370a3da6b178 | 0 | SemanticChunker@1.0.0 | b06ca74cce7d9f438a05945f22c72e86a8b6c8f482606c57bb704992e75dbe2c | ---
title: How can I find the date of n days ago from today using JavaScript?
shortTitle: Days ago from today
language: javascript
tags: [date]
cover: orange-wedges
excerpt: Calculate the date of `n` days ago from today or the date of `n` days from now.
listed: true
dateModified: 2024-01-07
---
As mentioned previously... | unknown | unknown | ---
title: How can I find the date of n days ago from today using JavaScript?
shortTitle: Days ago from today
language: javascript
tags: [date]
cover: orange-wedges
excerpt: Calculate the date of `n` days ago from today or the date of `n` days from now.
listed: true
dateModified: 2024-01-07
---
As mentioned previously... | ---
title: How can I find the date of n days ago from today using JavaScript?
shortTitle: Days ago from today
language: javascript
tags: [date]
cover: orange-wedges
excerpt: Calculate the date of `n` days ago from today or the date of `n` days from now.
listed: true
dateModified: 2024-01-07
---
As mentioned previously... | code_snippets | ||
2041a98b-2172-441a-b1f5-4b07b0c315b3 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/detect-undefined-object-property.md | unknown | e33340f8-fd44-49b5-beb5-816a872a8289 | 0 | SemanticChunker@1.0.0 | d36a50b8e2c4246986279b2d0fe67efd58dd1c8574501c10266d32bdb49408f8 | ---
title: How can I detect an undefined object property in JavaScript?
shortTitle: Detect undefined object property
language: javascript
tags: [object]
cover: pink-flower
excerpt: Learn how to detect `undefined` object properties in JavaScript the correct way.
listed: true
dateModified: 2022-08-07
---
It's not uncomm... | unknown | unknown | ---
title: How can I detect an undefined object property in JavaScript?
shortTitle: Detect undefined object property
language: javascript
tags: [object]
cover: pink-flower
excerpt: Learn how to detect `undefined` object properties in JavaScript the correct way.
listed: true
dateModified: 2022-08-07
---
It's not uncomm... | ---
title: How can I detect an undefined object property in JavaScript?
shortTitle: Detect undefined object property
language: javascript
tags: [object]
cover: pink-flower
excerpt: Learn how to detect `undefined` object properties in JavaScript the correct way.
listed: true
dateModified: 2022-08-07
---
It's not uncomm... | code_snippets | ||
e0fac044-4cce-4b42-ad78-dde6f58136af | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/detect-device-type.md | unknown | 86f1c8bf-dd68-42ca-88e0-ee78d5485d60 | 0 | SemanticChunker@1.0.0 | 484b3a54e7d15767803abfdefe42247c95cf22bf21479864279fd4461acf9e85 | ---
title: How can I detect the device type with JavaScript?
shortTitle: Detect device type
language: javascript
tags: [browser,regexp]
cover: clutter-2
excerpt: Learn how to detect whether a page is being viewed on a mobile device or a desktop.
listed: true
dateModified: 2024-06-03
---
Device detection is fairly usef... | unknown | unknown | ---
title: How can I detect the device type with JavaScript?
shortTitle: Detect device type
language: javascript
tags: [browser,regexp]
cover: clutter-2
excerpt: Learn how to detect whether a page is being viewed on a mobile device or a desktop.
listed: true
dateModified: 2024-06-03
---
Device detection is fairly usef... | ---
title: How can I detect the device type with JavaScript?
shortTitle: Detect device type
language: javascript
tags: [browser,regexp]
cover: clutter-2
excerpt: Learn how to detect whether a page is being viewed on a mobile device or a desktop.
listed: true
dateModified: 2024-06-03
---
Device detection is fairly usef... | code_snippets | ||
d0d204cf-dd4a-45b2-8e69-a722788d915f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/detect-caps-lock-is-on.md | unknown | d4365664-031b-4644-b33a-3430e9743d9e | 0 | SemanticChunker@1.0.0 | b587729ed2bf476eb83d0492335cf79f77a84ccecd346added92495b44a68b2b | ---
title: How can I detect if Caps Lock is on with JavaScript?
shortTitle: Detect Caps Lock
language: javascript
tags: [browser,event]
cover: keyboard
excerpt: If you need to check if Caps Lock is on when the user is typing in the browser, JavaScript's got you covered.
listed: true
dateModified: 2021-06-12
---
Oftent... | unknown | unknown | ---
title: How can I detect if Caps Lock is on with JavaScript?
shortTitle: Detect Caps Lock
language: javascript
tags: [browser,event]
cover: keyboard
excerpt: If you need to check if Caps Lock is on when the user is typing in the browser, JavaScript's got you covered.
listed: true
dateModified: 2021-06-12
---
Oftent... | ---
title: How can I detect if Caps Lock is on with JavaScript?
shortTitle: Detect Caps Lock
language: javascript
tags: [browser,event]
cover: keyboard
excerpt: If you need to check if Caps Lock is on when the user is typing in the browser, JavaScript's got you covered.
listed: true
dateModified: 2021-06-12
---
Oftent... | code_snippets | ||
700b1674-7d75-4790-ac27-3f0b7634f208 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/distance-of-two-lat-lng-coordinates.md | unknown | 4a090618-30e4-4222-9fdf-d9d2f1dabbd7 | 1 | SemanticChunker@1.0.0 | ee7ba41305a496591fa56a550b6478c30c23b16bbb6239bcdbeeae3d9c4414a3 | @[Further reading](/js/s/convert-degrees-radians)
We'll also need to find the **differences in latitude and longitude between the two points**. Then, we can apply the Haversine formula to calculate the distance.
```js
const coordinateDistance = (lat1, lon1, lat2, lon2) => {
// Convert degrees to radians
const radLa... | unknown | unknown | @[Further reading](/js/s/convert-degrees-radians)
We'll also need to find the **differences in latitude and longitude between the two points**. Then, we can apply the Haversine formula to calculate the distance.
```js
const coordinateDistance = (lat1, lon1, lat2, lon2) => {
// Convert degrees to radians
const radLa... | @[Further reading](/js/s/convert-degrees-radians)
We'll also need to find the **differences in latitude and longitude between the two points**. Then, we can apply the Haversine formula to calculate the distance.
```js
const coordinateDistance = (lat1, lon1, lat2, lon2) => {
// Convert degrees to radians
const radLa... | code_snippets | ||
e8e76cad-6a04-4a40-852c-51ff2cabca79 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/distance-of-two-lat-lng-coordinates.md | unknown | 4a090618-30e4-4222-9fdf-d9d2f1dabbd7 | 0 | SemanticChunker@1.0.0 | a940c056017dac0b8e27fd5e09e4ae1ccb2d67a0951f4fd0d9c45b0f18d1ed6f | ---
title: How can I calculate the distance between two coordinates using JavaScript?
shortTitle: Distance between two coordinates
language: javascript
tags: [math]
cover: angry-waves
excerpt: Given two pairs of latitude and longitude coordinates, you can calculate the distance between them using the Haversine formula.... | unknown | unknown | ---
title: How can I calculate the distance between two coordinates using JavaScript?
shortTitle: Distance between two coordinates
language: javascript
tags: [math]
cover: angry-waves
excerpt: Given two pairs of latitude and longitude coordinates, you can calculate the distance between them using the Haversine formula.... | ---
title: How can I calculate the distance between two coordinates using JavaScript?
shortTitle: Distance between two coordinates
language: javascript
tags: [math]
cover: angry-waves
excerpt: Given two pairs of latitude and longitude coordinates, you can calculate the distance between them using the Haversine formula.... | code_snippets | ||
1e9c37dd-f740-4a3a-9fe8-3b17887d3035 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/destructuring-assignment.md | unknown | e4e5d08c-07db-42bd-b9d6-4f18b547c1f4 | 4 | SemanticChunker@1.0.0 | 16391a196d5d2831a33f1b0714a6363a6ab5a57c66c2f589caff6b8cd538cfaf | [Array destructuring > Advanced destructuring]
## Advanced destructuring
As arrays act much like objects, it's possible to use the destructuring assignment syntax to get specific values from an array by using the index as a key in an object destructuring assignment. Additionally, using this method, you can get other ... | unknown | unknown | [Array destructuring > Advanced destructuring]
## Advanced destructuring
As arrays act much like objects, it's possible to use the destructuring assignment syntax to get specific values from an array by using the index as a key in an object destructuring assignment. Additionally, using this method, you can get other ... | [Array destructuring > Advanced destructuring]
## Advanced destructuring
As arrays act much like objects, it's possible to use the destructuring assignment syntax to get specific values from an array by using the index as a key in an object destructuring assignment. Additionally, using this method, you can get other ... | code_snippets | ||
a7a27de3-b400-4282-9dd3-10125d0e22c7 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/destructuring-assignment.md | unknown | e4e5d08c-07db-42bd-b9d6-4f18b547c1f4 | 2 | SemanticChunker@1.0.0 | ae83b4bb3cb835cddcfc50698d9376c5e4cce6e8248968bf15064c33554d1c8b | [Array destructuring > Object destructuring]
## Object destructuring
Object destructuring is pretty similar to array destructuring, the main difference being that you can reference each key in the object by name, creating a variable with the same name. Additionally, you can also unpack a key to a new variable name, u... | unknown | unknown | [Array destructuring > Object destructuring]
## Object destructuring
Object destructuring is pretty similar to array destructuring, the main difference being that you can reference each key in the object by name, creating a variable with the same name. Additionally, you can also unpack a key to a new variable name, u... | [Array destructuring > Object destructuring]
## Object destructuring
Object destructuring is pretty similar to array destructuring, the main difference being that you can reference each key in the object by name, creating a variable with the same name. Additionally, you can also unpack a key to a new variable name, u... | code_snippets | ||
c35ac262-fe8f-4ac7-9ed5-401944c715dd | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/destructuring-assignment.md | unknown | e4e5d08c-07db-42bd-b9d6-4f18b547c1f4 | 0 | SemanticChunker@1.0.0 | 5446fb0f5f5bc409db405a4bda7d0d032bd79212f186fe4566afaa6e2cb719cc | ---
title: Where and how can I use the destructuring assignment syntax in JavaScript?
shortTitle: Destructuring assignment introduction
language: javascript
tags: [array,object]
cover: building-blocks
excerpt: Learn the basics of the destructuring assignment syntax in JavaScript ES6 and improve your code with this easy... | unknown | unknown | ---
title: Where and how can I use the destructuring assignment syntax in JavaScript?
shortTitle: Destructuring assignment introduction
language: javascript
tags: [array,object]
cover: building-blocks
excerpt: Learn the basics of the destructuring assignment syntax in JavaScript ES6 and improve your code with this easy... | ---
title: Where and how can I use the destructuring assignment syntax in JavaScript?
shortTitle: Destructuring assignment introduction
language: javascript
tags: [array,object]
cover: building-blocks
excerpt: Learn the basics of the destructuring assignment syntax in JavaScript ES6 and improve your code with this easy... | code_snippets | ||
cb565341-37c4-4190-a7a3-bd02ae79fd41 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/destructuring-assignment.md | unknown | e4e5d08c-07db-42bd-b9d6-4f18b547c1f4 | 3 | SemanticChunker@1.0.0 | 33a23a88de44e8f8c05514e705977905dc875bdc47b4f3aab9cd6114f4135cc6 | [Array destructuring > Nested destructuring]
## Nested destructuring
Nested objects and arrays can be unpacked by following the same rules. The difference here is that you can unpack nested keys or values directly to variables without having to store the parent object in a variable itself.
```js
const nested = { a: ... | unknown | unknown | [Array destructuring > Nested destructuring]
## Nested destructuring
Nested objects and arrays can be unpacked by following the same rules. The difference here is that you can unpack nested keys or values directly to variables without having to store the parent object in a variable itself.
```js
const nested = { a: ... | [Array destructuring > Nested destructuring]
## Nested destructuring
Nested objects and arrays can be unpacked by following the same rules. The difference here is that you can unpack nested keys or values directly to variables without having to store the parent object in a variable itself.
```js
const nested = { a: ... | code_snippets | ||
f2bd9596-140c-490a-8f8f-6171f55ccfd9 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/destructuring-assignment.md | unknown | e4e5d08c-07db-42bd-b9d6-4f18b547c1f4 | 1 | SemanticChunker@1.0.0 | 4f2c4a11f07ef78144f8b638c197c6eac83ade308a3247272ca4c34f45f1d485 | [Array destructuring]
## Array destructuring
Destructuring an array is very straightforward. All you have to do is declare a variable for each value in the sequence. You can define fewer variables than there are indexes in the array (i.e. if you only want to unpack the first few values), skip some indexes or even use... | unknown | unknown | [Array destructuring]
## Array destructuring
Destructuring an array is very straightforward. All you have to do is declare a variable for each value in the sequence. You can define fewer variables than there are indexes in the array (i.e. if you only want to unpack the first few values), skip some indexes or even use... | [Array destructuring]
## Array destructuring
Destructuring an array is very straightforward. All you have to do is declare a variable for each value in the sequence. You can define fewer variables than there are indexes in the array (i.e. if you only want to unpack the first few values), skip some indexes or even use... | code_snippets | ||
28954671-f7fd-49b2-be76-c69d5b1434f2 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/defer-function.md | unknown | a67e62c4-a1dd-4d5d-a44b-5addd1da649d | 0 | SemanticChunker@1.0.0 | e5482103b3f4f47e57688681f41a6a367199db08693e856ecb04f2671e672b69 | ---
title: Defer a JavaScript function
shortTitle: Defer function
language: javascript
tags: [function]
cover: shiny-mountains
excerpt: Defer the invocation of a function until the current call stack has been cleared.
listed: true
dateModified: 2024-07-24
---
Oftentimes, non-critical tasks can be deferred to improve t... | unknown | unknown | ---
title: Defer a JavaScript function
shortTitle: Defer function
language: javascript
tags: [function]
cover: shiny-mountains
excerpt: Defer the invocation of a function until the current call stack has been cleared.
listed: true
dateModified: 2024-07-24
---
Oftentimes, non-critical tasks can be deferred to improve t... | ---
title: Defer a JavaScript function
shortTitle: Defer function
language: javascript
tags: [function]
cover: shiny-mountains
excerpt: Defer the invocation of a function until the current call stack has been cleared.
listed: true
dateModified: 2024-07-24
---
Oftentimes, non-critical tasks can be deferred to improve t... | code_snippets | ||
0b24dec4-96b6-45cf-a6e6-887fd5ce5a23 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/deep-freeze-object.md | unknown | fa01fd0e-2f9c-4ea1-b662-a3338b369da9 | 6 | SemanticChunker@1.0.0 | b6ea7fa4b02bca57123cb471861fc830d8aa0d2951f8a7f8a9075574b4b7c06a | [Freezing complex objects > Freezing a `Set` object]
### Freezing a `Set` object
In order to freeze a `Set` object, you can simply set the `Set.prototype.add()`, `Set.prototype.delete()` and `Set.prototype.clear()` methods to `undefined`. This will effectively prevent them from being used, practically freezing the ob... | unknown | unknown | [Freezing complex objects > Freezing a `Set` object]
### Freezing a `Set` object
In order to freeze a `Set` object, you can simply set the `Set.prototype.add()`, `Set.prototype.delete()` and `Set.prototype.clear()` methods to `undefined`. This will effectively prevent them from being used, practically freezing the ob... | [Freezing complex objects > Freezing a `Set` object]
### Freezing a `Set` object
In order to freeze a `Set` object, you can simply set the `Set.prototype.add()`, `Set.prototype.delete()` and `Set.prototype.clear()` methods to `undefined`. This will effectively prevent them from being used, practically freezing the ob... | code_snippets | ||
67d1610c-288f-4140-a64e-b2ef23ce4b2e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/deep-freeze-object.md | unknown | fa01fd0e-2f9c-4ea1-b662-a3338b369da9 | 4 | SemanticChunker@1.0.0 | 268ec996f04c68b30c33f7ce534d7132a24e135ff025c6452ec3b09cb783bff3 | [Deep freezing an object > Checking if an object is deep frozen]
### Checking if an object is deep frozen
Checking if an object is frozen is simple, using `Object.isFrozen()`. However, to check if an object is deeply frozen, you will have to perform a **recursive check** on all its properties. This is very similar to... | unknown | unknown | [Deep freezing an object > Checking if an object is deep frozen]
### Checking if an object is deep frozen
Checking if an object is frozen is simple, using `Object.isFrozen()`. However, to check if an object is deeply frozen, you will have to perform a **recursive check** on all its properties. This is very similar to... | [Deep freezing an object > Checking if an object is deep frozen]
### Checking if an object is deep frozen
Checking if an object is frozen is simple, using `Object.isFrozen()`. However, to check if an object is deeply frozen, you will have to perform a **recursive check** on all its properties. This is very similar to... | code_snippets | ||
6b4646da-f85c-41b8-a0ca-c8e7d41debff | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/deep-freeze-object.md | unknown | fa01fd0e-2f9c-4ea1-b662-a3338b369da9 | 5 | SemanticChunker@1.0.0 | bd59ca296157fdb95c6719eda30ed27b7ec0f5a7a72a114c1df07de52936dd41 | [`Object.freeze()` vs `Object.seal()` > Freezing complex objects]
## Freezing complex objects
For **non-plain objects**, such as `Set` or `Map`, you can override their methods to prevent them from being used. This effectively freezes the object, preventing any changes to it.
> [!NOTE]
>
> `Set` and `Map` are used as... | unknown | unknown | [`Object.freeze()` vs `Object.seal()` > Freezing complex objects]
## Freezing complex objects
For **non-plain objects**, such as `Set` or `Map`, you can override their methods to prevent them from being used. This effectively freezes the object, preventing any changes to it.
> [!NOTE]
>
> `Set` and `Map` are used as... | [`Object.freeze()` vs `Object.seal()` > Freezing complex objects]
## Freezing complex objects
For **non-plain objects**, such as `Set` or `Map`, you can override their methods to prevent them from being used. This effectively freezes the object, preventing any changes to it.
> [!NOTE]
>
> `Set` and `Map` are used as... | code_snippets | ||
839ba593-4792-44ca-9343-e4b7ba76b069 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/deep-freeze-object.md | unknown | fa01fd0e-2f9c-4ea1-b662-a3338b369da9 | 1 | SemanticChunker@1.0.0 | 448b3f9f9d30bbb40d8dc5c825bf0af432abd8244aca5028f5736bae8a6da3cf | [`Object.freeze()` vs `Object.seal()`]
## `Object.freeze()` vs `Object.seal()`
In order to make an object **immutable**, you can use either `Object.freeze()` and `Object.seal()`. Although similar, they have a key difference that you need to remember.
```js
const frozen = Object.freeze({ username: 'johnsmith' });
con... | unknown | unknown | [`Object.freeze()` vs `Object.seal()`]
## `Object.freeze()` vs `Object.seal()`
In order to make an object **immutable**, you can use either `Object.freeze()` and `Object.seal()`. Although similar, they have a key difference that you need to remember.
```js
const frozen = Object.freeze({ username: 'johnsmith' });
con... | [`Object.freeze()` vs `Object.seal()`]
## `Object.freeze()` vs `Object.seal()`
In order to make an object **immutable**, you can use either `Object.freeze()` and `Object.seal()`. Although similar, they have a key difference that you need to remember.
```js
const frozen = Object.freeze({ username: 'johnsmith' });
con... | code_snippets | ||
8a27b686-1941-461c-adc1-4b10abf8d4be | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/deep-freeze-object.md | unknown | fa01fd0e-2f9c-4ea1-b662-a3338b369da9 | 0 | SemanticChunker@1.0.0 | a459541a15fa254c0a863860832d8e4bac268d7c744f956fb02cd3d008b844aa | ---
title: How can I deep freeze an object in JavaScript?
shortTitle: Deep freeze object
language: javascript
tags: [object,recursion]
cover: frozen-globe
excerpt: Learn how mutability works in JavaScript, its applications to objects and how you can properly freeze them to make them constant.
listed: true
dateModified:... | unknown | unknown | ---
title: How can I deep freeze an object in JavaScript?
shortTitle: Deep freeze object
language: javascript
tags: [object,recursion]
cover: frozen-globe
excerpt: Learn how mutability works in JavaScript, its applications to objects and how you can properly freeze them to make them constant.
listed: true
dateModified:... | ---
title: How can I deep freeze an object in JavaScript?
shortTitle: Deep freeze object
language: javascript
tags: [object,recursion]
cover: frozen-globe
excerpt: Learn how mutability works in JavaScript, its applications to objects and how you can properly freeze them to make them constant.
listed: true
dateModified:... | code_snippets | ||
bd07f840-8054-430b-821c-a4ca7900d6ca | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/deep-freeze-object.md | unknown | fa01fd0e-2f9c-4ea1-b662-a3338b369da9 | 7 | SemanticChunker@1.0.0 | 90c281f4eabb2632e7b8a7ee39a0c6d7c86d1c07fe50b596bc1bedec0df1d7be | [Freezing complex objects > Freezing a `Map` object]
### Freezing a `Map` object
Freezing a `Map` object is very similar to freezing a `Set` object. You can set the `Map.prototype.set()`, `Map.prototype.delete()` and `Map.prototype.clear()` methods to `undefined` and then use `Object.freeze()` to freeze the `Map` obj... | unknown | unknown | [Freezing complex objects > Freezing a `Map` object]
### Freezing a `Map` object
Freezing a `Map` object is very similar to freezing a `Set` object. You can set the `Map.prototype.set()`, `Map.prototype.delete()` and `Map.prototype.clear()` methods to `undefined` and then use `Object.freeze()` to freeze the `Map` obj... | [Freezing complex objects > Freezing a `Map` object]
### Freezing a `Map` object
Freezing a `Map` object is very similar to freezing a `Set` object. You can set the `Map.prototype.set()`, `Map.prototype.delete()` and `Map.prototype.clear()` methods to `undefined` and then use `Object.freeze()` to freeze the `Map` obj... | code_snippets | ||
e921e57c-05be-4ecd-b547-727d79809e5b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/deep-freeze-object.md | unknown | fa01fd0e-2f9c-4ea1-b662-a3338b369da9 | 3 | SemanticChunker@1.0.0 | 5cfeeb8a1d2b1ce4fcdff86b33ca44ac7ab7b4cb4cef829941c7efd42f5222cb | [Deep freezing an object > Frozen objects in strict mode]
### Frozen objects in strict mode
As a side note, if your code is running in **strict mode**, frozen objects will **throw an error** when trying to modify them. This makes it easier to catch bugs, as you will be notified immediately if you try to change a froz... | unknown | unknown | [Deep freezing an object > Frozen objects in strict mode]
### Frozen objects in strict mode
As a side note, if your code is running in **strict mode**, frozen objects will **throw an error** when trying to modify them. This makes it easier to catch bugs, as you will be notified immediately if you try to change a froz... | [Deep freezing an object > Frozen objects in strict mode]
### Frozen objects in strict mode
As a side note, if your code is running in **strict mode**, frozen objects will **throw an error** when trying to modify them. This makes it easier to catch bugs, as you will be notified immediately if you try to change a froz... | code_snippets | ||
ea8c66ec-e72d-4c3f-8406-6725380400a1 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/deep-freeze-object.md | unknown | fa01fd0e-2f9c-4ea1-b662-a3338b369da9 | 2 | SemanticChunker@1.0.0 | a5e88ab73924d0c2ca7328d0bbd5e6782beafc6be8acea278c618fb4af6c733c | [`Object.freeze()` vs `Object.seal()` > Deep freezing an object]
## Deep freezing an object
Both of the aforementioned methods perform a **shallow freeze** on the object. This means that **nested objects and arrays** are not frozen and can be mutated.
```js
const myObj = {
a: 1,
b: 'hello',
c: [0, 1, 2],
d: { e:... | unknown | unknown | [`Object.freeze()` vs `Object.seal()` > Deep freezing an object]
## Deep freezing an object
Both of the aforementioned methods perform a **shallow freeze** on the object. This means that **nested objects and arrays** are not frozen and can be mutated.
```js
const myObj = {
a: 1,
b: 'hello',
c: [0, 1, 2],
d: { e:... | [`Object.freeze()` vs `Object.seal()` > Deep freezing an object]
## Deep freezing an object
Both of the aforementioned methods perform a **shallow freeze** on the object. This means that **nested objects and arrays** are not frozen and can be mutated.
```js
const myObj = {
a: 1,
b: 'hello',
c: [0, 1, 2],
d: { e:... | code_snippets | ||
08463f2e-e02c-4a7f-8a19-26533ac9cde2 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/default-values-for-object-properties.md | unknown | 7e292b3b-c15d-4a77-b6c2-a4abfbe9c6be | 0 | SemanticChunker@1.0.0 | fe3759f058e3e5c13dc7bac2e3cbbeb35cc24e8b2184d5372b056fac018c5924 | ---
title: Assign default values for a JavaScript object's properties
shortTitle: Default values for object properties
language: javascript
tags: [object]
cover: filter-coffee-pot
excerpt: Assign default values for all properties in an object that are `undefined`.
listed: true
dateModified: 2024-07-17
---
If you have ... | unknown | unknown | ---
title: Assign default values for a JavaScript object's properties
shortTitle: Default values for object properties
language: javascript
tags: [object]
cover: filter-coffee-pot
excerpt: Assign default values for all properties in an object that are `undefined`.
listed: true
dateModified: 2024-07-17
---
If you have ... | ---
title: Assign default values for a JavaScript object's properties
shortTitle: Default values for object properties
language: javascript
tags: [object]
cover: filter-coffee-pot
excerpt: Assign default values for all properties in an object that are `undefined`.
listed: true
dateModified: 2024-07-17
---
If you have ... | code_snippets | ||
00694604-5796-4370-a698-53c8447a6ea6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/digitize-number.md | unknown | 02015218-83d1-4856-9f48-f4d015b9419e | 2 | SemanticChunker@1.0.0 | c333b2b20cab53ca2ed658ea89dcb12e89dd00e92763cc85c2395a6ad4e72653 | [Digitize a number > Sum of digits]
## Sum of digits
If you want to **sum the digits** of a number, you can use `Array.prototype.reduce()` on the array of digits. This will allow you to accumulate the sum of all digits in a single pass.
```js
const sumDigits = n =>
digitize(n).reduce((acc, curr) => acc + curr, 0);
... | unknown | unknown | [Digitize a number > Sum of digits]
## Sum of digits
If you want to **sum the digits** of a number, you can use `Array.prototype.reduce()` on the array of digits. This will allow you to accumulate the sum of all digits in a single pass.
```js
const sumDigits = n =>
digitize(n).reduce((acc, curr) => acc + curr, 0);
... | [Digitize a number > Sum of digits]
## Sum of digits
If you want to **sum the digits** of a number, you can use `Array.prototype.reduce()` on the array of digits. This will allow you to accumulate the sum of all digits in a single pass.
```js
const sumDigits = n =>
digitize(n).reduce((acc, curr) => acc + curr, 0);
... | code_snippets | ||
22c46af4-7c61-4fc0-a335-0d71a9d55470 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/digitize-number.md | unknown | 02015218-83d1-4856-9f48-f4d015b9419e | 3 | SemanticChunker@1.0.0 | fef4a09415df386a82298fb5b3f76bc599284b8657c439d304e6ee0ff74ec66a | [Digitize a number > Digital root]
## Digital root
The **digital root** of a number is the single-digit value obtained by an iterative process of summing digits, until a single-digit number is achieved. You can compute the digital root using the `sumDigits` function in a loop until the result is a single digit.
```j... | unknown | unknown | [Digitize a number > Digital root]
## Digital root
The **digital root** of a number is the single-digit value obtained by an iterative process of summing digits, until a single-digit number is achieved. You can compute the digital root using the `sumDigits` function in a loop until the result is a single digit.
```j... | [Digitize a number > Digital root]
## Digital root
The **digital root** of a number is the single-digit value obtained by an iterative process of summing digits, until a single-digit number is achieved. You can compute the digital root using the `sumDigits` function in a loop until the result is a single digit.
```j... | code_snippets | ||
c8ff71ac-c40a-4d1a-920b-a915f2baf8cf | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/digitize-number.md | unknown | 02015218-83d1-4856-9f48-f4d015b9419e | 1 | SemanticChunker@1.0.0 | eb44f0a0c1518de5265e2499330cbd92f64e6768ada6d24048255845fce19c25 | [Digitize a number]
## Digitize a number
For starters, any number can be converted to a string using the **template literal syntax**. Converting a string to an **array of characters** is as simple as using the spread operator (`...`). Then, to convert a character into a number, you can use `Number.parseInt()`. Finall... | unknown | unknown | [Digitize a number]
## Digitize a number
For starters, any number can be converted to a string using the **template literal syntax**. Converting a string to an **array of characters** is as simple as using the spread operator (`...`). Then, to convert a character into a number, you can use `Number.parseInt()`. Finall... | [Digitize a number]
## Digitize a number
For starters, any number can be converted to a string using the **template literal syntax**. Converting a string to an **array of characters** is as simple as using the spread operator (`...`). Then, to convert a character into a number, you can use `Number.parseInt()`. Finall... | code_snippets | ||
e6542b43-3b9d-4642-9afb-58b63647cad6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/digitize-number.md | unknown | 02015218-83d1-4856-9f48-f4d015b9419e | 0 | SemanticChunker@1.0.0 | ddf575a26293e78ce8fcd1429711571994eb6c80c137fc6d74c19f272adb49c2 | ---
title: Digitize a number in JavaScript
shortTitle: Digitize number
language: javascript
tags: [number]
cover: industrial-tokyo
excerpt: Learn how to convert any number to an array of digits, as well as how to sum the digits and compute the digital root efficiently.
listed: true
dateModified: 2025-06-15
---
Convert... | unknown | unknown | ---
title: Digitize a number in JavaScript
shortTitle: Digitize number
language: javascript
tags: [number]
cover: industrial-tokyo
excerpt: Learn how to convert any number to an array of digits, as well as how to sum the digits and compute the digital root efficiently.
listed: true
dateModified: 2025-06-15
---
Convert... | ---
title: Digitize a number in JavaScript
shortTitle: Digitize number
language: javascript
tags: [number]
cover: industrial-tokyo
excerpt: Learn how to convert any number to an array of digits, as well as how to sum the digits and compute the digital root efficiently.
listed: true
dateModified: 2025-06-15
---
Convert... | code_snippets | ||
28acb498-8d0e-4f37-9a30-d54ea4e37c3f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/deep-clone-structured-clone.md | unknown | 97ed13ca-144d-4056-8cce-7cae948fafd5 | 8 | SemanticChunker@1.0.0 | 218cabce77e624112a291187e7e0f0e526135213e077c9cf6e03ca6217b26b13 | [Built-in types > Symbol properties]
### Symbol properties
`structuredClone()` **does not clone properties keyed by Symbols**. Instead, it ignores them, just like `JSON.stringify()`. Shallow and custom deep clones copy Symbol properties as references.
```js
const sym = Symbol('key');
const obj = { [sym]: 'value' };
... | unknown | unknown | [Built-in types > Symbol properties]
### Symbol properties
`structuredClone()` **does not clone properties keyed by Symbols**. Instead, it ignores them, just like `JSON.stringify()`. Shallow and custom deep clones copy Symbol properties as references.
```js
const sym = Symbol('key');
const obj = { [sym]: 'value' };
... | [Built-in types > Symbol properties]
### Symbol properties
`structuredClone()` **does not clone properties keyed by Symbols**. Instead, it ignores them, just like `JSON.stringify()`. Shallow and custom deep clones copy Symbol properties as references.
```js
const sym = Symbol('key');
const obj = { [sym]: 'value' };
... | code_snippets | ||
35859f08-d00d-4e41-b6c6-b712f35be11c | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/deep-clone-structured-clone.md | unknown | 97ed13ca-144d-4056-8cce-7cae948fafd5 | 4 | SemanticChunker@1.0.0 | 9fe534f4dbeb8c1ddf18869b652ef71cc64707a0d90e8a4e4e06c238e0960b32 | [Built-in types > DOM nodes]
### DOM nodes
**DOM nodes cannot be cloned** with `structuredClone()`. Attempting to do so throws a `DataCloneError`. This makes sense when you consider what it means to clone a DOM node: it would require creating a new node in the document. Other options don't handle this gracefully eith... | unknown | unknown | [Built-in types > DOM nodes]
### DOM nodes
**DOM nodes cannot be cloned** with `structuredClone()`. Attempting to do so throws a `DataCloneError`. This makes sense when you consider what it means to clone a DOM node: it would require creating a new node in the document. Other options don't handle this gracefully eith... | [Built-in types > DOM nodes]
### DOM nodes
**DOM nodes cannot be cloned** with `structuredClone()`. Attempting to do so throws a `DataCloneError`. This makes sense when you consider what it means to clone a DOM node: it would require creating a new node in the document. Other options don't handle this gracefully eith... | code_snippets | ||
3d249381-d360-4ebe-9dee-e3bd16a1e5e9 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/deep-clone-structured-clone.md | unknown | 97ed13ca-144d-4056-8cce-7cae948fafd5 | 3 | SemanticChunker@1.0.0 | d4ec82e0eed4be0813fc82fd536bab08db6ddc42aea8acb352363b1ec8fa4840 | [Cloning methods overview > Built-in types]
### Built-in types
Built-in objects, like `Date`, `Map`, `Set`, and `RegExp`, are not cloned correctly by `JSON.stringify()`. They are either converted to strings or empty objects. Shallow clones copy **references**, while custom deep clones may fail unless specifically han... | unknown | unknown | [Cloning methods overview > Built-in types]
### Built-in types
Built-in objects, like `Date`, `Map`, `Set`, and `RegExp`, are not cloned correctly by `JSON.stringify()`. They are either converted to strings or empty objects. Shallow clones copy **references**, while custom deep clones may fail unless specifically han... | [Cloning methods overview > Built-in types]
### Built-in types
Built-in objects, like `Date`, `Map`, `Set`, and `RegExp`, are not cloned correctly by `JSON.stringify()`. They are either converted to strings or empty objects. Shallow clones copy **references**, while custom deep clones may fail unless specifically han... | code_snippets | ||
4e1b5941-112d-41b6-8f23-d86c8fec1d9a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/deep-clone-structured-clone.md | unknown | 97ed13ca-144d-4056-8cce-7cae948fafd5 | 1 | SemanticChunker@1.0.0 | 2081b8d291b696ce618c1c0a0c9d53490d47c90286f6f2da9d1eb0fdb9296bb6 | [Cloning methods overview]
## Cloning methods overview
Let's start by comparing the available cloning methods. For simplicity, we'll look at **four common approaches**, as shown below:
```js collapse={4-15}
const shallowClone = obj => ({ ...obj });
const deepClone = obj => {
if (obj === null) return null;
let clo... | unknown | unknown | [Cloning methods overview]
## Cloning methods overview
Let's start by comparing the available cloning methods. For simplicity, we'll look at **four common approaches**, as shown below:
```js collapse={4-15}
const shallowClone = obj => ({ ...obj });
const deepClone = obj => {
if (obj === null) return null;
let clo... | [Cloning methods overview]
## Cloning methods overview
Let's start by comparing the available cloning methods. For simplicity, we'll look at **four common approaches**, as shown below:
```js collapse={4-15}
const shallowClone = obj => ({ ...obj });
const deepClone = obj => {
if (obj === null) return null;
let clo... | code_snippets | ||
649aadf2-da81-40e6-bcd2-5d0e4dc687ca | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/deep-clone-structured-clone.md | unknown | 97ed13ca-144d-4056-8cce-7cae948fafd5 | 6 | SemanticChunker@1.0.0 | 52bda890ef2f48a89062c3f8158236f6d898724421ba34a45fbbf3bea484f589 | [Built-in types > Prototype chain]
### Prototype chain
The most surprising letdown of `structuredClone()` is that it **does not preserve the prototype chain**. The cloned object always has `Object.prototype` as its prototype, regardless of the original object's prototype. Yet, none of the other methods preserve the p... | unknown | unknown | [Built-in types > Prototype chain]
### Prototype chain
The most surprising letdown of `structuredClone()` is that it **does not preserve the prototype chain**. The cloned object always has `Object.prototype` as its prototype, regardless of the original object's prototype. Yet, none of the other methods preserve the p... | [Built-in types > Prototype chain]
### Prototype chain
The most surprising letdown of `structuredClone()` is that it **does not preserve the prototype chain**. The cloned object always has `Object.prototype` as its prototype, regardless of the original object's prototype. Yet, none of the other methods preserve the p... | code_snippets | ||
77358830-0243-49be-a1da-e5694850a8d3 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/deep-clone-structured-clone.md | unknown | 97ed13ca-144d-4056-8cce-7cae948fafd5 | 11 | SemanticChunker@1.0.0 | 169f266b6426ccce16836f8ca1029c5b96c136cdfe934af9ad5c474f185329db | [Cloning methods overview > When to use `structuredClone()`]
## When to use `structuredClone()`
As mentioned already, `structuredClone()` is a **powerful tool for deep cloning objects in JavaScript**, natively, without hassle and headaches. That being said, if you don't explicitly need to handle some special edge cas... | unknown | unknown | [Cloning methods overview > When to use `structuredClone()`]
## When to use `structuredClone()`
As mentioned already, `structuredClone()` is a **powerful tool for deep cloning objects in JavaScript**, natively, without hassle and headaches. That being said, if you don't explicitly need to handle some special edge cas... | [Cloning methods overview > When to use `structuredClone()`]
## When to use `structuredClone()`
As mentioned already, `structuredClone()` is a **powerful tool for deep cloning objects in JavaScript**, natively, without hassle and headaches. That being said, if you don't explicitly need to handle some special edge cas... | code_snippets | ||
77620f17-0a78-40d8-9945-b2e03ee12b53 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/deep-clone-structured-clone.md | unknown | 97ed13ca-144d-4056-8cce-7cae948fafd5 | 10 | SemanticChunker@1.0.0 | 4856b986a8119fd8d79fc0a0f55775ecf744140363dd59ca837a67a51ef84e01 | [Cloning methods overview > Performance considerations]
## Performance considerations
Given the fact that `structuredClone()` is a built-in method, it is generally **optimized for performance**. It is faster than custom deep clone functions and `JSON.stringify()`, especially for complex objects with circular referenc... | unknown | unknown | [Cloning methods overview > Performance considerations]
## Performance considerations
Given the fact that `structuredClone()` is a built-in method, it is generally **optimized for performance**. It is faster than custom deep clone functions and `JSON.stringify()`, especially for complex objects with circular referenc... | [Cloning methods overview > Performance considerations]
## Performance considerations
Given the fact that `structuredClone()` is a built-in method, it is generally **optimized for performance**. It is faster than custom deep clone functions and `JSON.stringify()`, especially for complex objects with circular referenc... | code_snippets | ||
7bc4e8a6-b399-47f7-afbf-8d09e19a10e5 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/deep-clone-structured-clone.md | unknown | 97ed13ca-144d-4056-8cce-7cae948fafd5 | 9 | SemanticChunker@1.0.0 | 3eec9d71587acbf9e9b95c39f0b53596d5da4569dbeffa63073103cd915908dd | [Built-in types > Private fields]
### Private fields
**Private class fields and methods are also not cloned** by `structuredClone()`. Only public, enumerable properties are included in the clone. This is consistent with how other methods handle private properties, as they are not part of the object's enumerable prope... | unknown | unknown | [Built-in types > Private fields]
### Private fields
**Private class fields and methods are also not cloned** by `structuredClone()`. Only public, enumerable properties are included in the clone. This is consistent with how other methods handle private properties, as they are not part of the object's enumerable prope... | [Built-in types > Private fields]
### Private fields
**Private class fields and methods are also not cloned** by `structuredClone()`. Only public, enumerable properties are included in the clone. This is consistent with how other methods handle private properties, as they are not part of the object's enumerable prope... | code_snippets | ||
8557de1f-5a5b-4ed6-972d-ebfdc9f0547e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/deep-clone-structured-clone.md | unknown | 97ed13ca-144d-4056-8cce-7cae948fafd5 | 0 | SemanticChunker@1.0.0 | fb70911dde5ae06a20efe6321402b0ce2a8cdfa0d97b8bbbad2cc6297a104cae | ---
title: How does JavaScript's structuredClone() differ from other cloning methods?
shortTitle: Deep clone with structuredClone()
language: javascript
tags: [object]
cover: cherry-blossom-boats
excerpt: Learn how to deep clone objects in JavaScript using structuredClone, and how it compares to other cloning methods.
... | unknown | unknown | ---
title: How does JavaScript's structuredClone() differ from other cloning methods?
shortTitle: Deep clone with structuredClone()
language: javascript
tags: [object]
cover: cherry-blossom-boats
excerpt: Learn how to deep clone objects in JavaScript using structuredClone, and how it compares to other cloning methods.
... | ---
title: How does JavaScript's structuredClone() differ from other cloning methods?
shortTitle: Deep clone with structuredClone()
language: javascript
tags: [object]
cover: cherry-blossom-boats
excerpt: Learn how to deep clone objects in JavaScript using structuredClone, and how it compares to other cloning methods.
... | code_snippets | ||
c0a7df06-c9e1-4a61-97b7-70df3786bd69 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/deep-clone-structured-clone.md | unknown | 97ed13ca-144d-4056-8cce-7cae948fafd5 | 7 | SemanticChunker@1.0.0 | f1825319ee9f1912c710c083c5f3d2512f98e06d4df8c9a6c8219c854c234024 | [Built-in types > Getters and setters]
### Getters and setters
Another shortcoming shared among all options, including `structuredClone()`, is that **getters and setters are not preserved**. Instead, only the current value is cloned, which means that the cloned object does not have the same accessors as the original.... | unknown | unknown | [Built-in types > Getters and setters]
### Getters and setters
Another shortcoming shared among all options, including `structuredClone()`, is that **getters and setters are not preserved**. Instead, only the current value is cloned, which means that the cloned object does not have the same accessors as the original.... | [Built-in types > Getters and setters]
### Getters and setters
Another shortcoming shared among all options, including `structuredClone()`, is that **getters and setters are not preserved**. Instead, only the current value is cloned, which means that the cloned object does not have the same accessors as the original.... | code_snippets | ||
d2b4f49c-3bca-465e-bd3d-470e35915e91 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/deep-clone-structured-clone.md | unknown | 97ed13ca-144d-4056-8cce-7cae948fafd5 | 12 | SemanticChunker@1.0.0 | 8d7d1b7e33b0c3fba6ef42dd8e016680e8d453bb063bb07ee1ffaf4444ec5171 | [Cloning methods overview > Conclusion]
## Conclusion
In conclusion, `structuredClone()` is a **powerful and versatile method for deep cloning objects in JavaScript**. It handles many edge cases that other methods struggle with, such as circular references, built-in types, and complex data structures. While it has so... | unknown | unknown | [Cloning methods overview > Conclusion]
## Conclusion
In conclusion, `structuredClone()` is a **powerful and versatile method for deep cloning objects in JavaScript**. It handles many edge cases that other methods struggle with, such as circular references, built-in types, and complex data structures. While it has so... | [Cloning methods overview > Conclusion]
## Conclusion
In conclusion, `structuredClone()` is a **powerful and versatile method for deep cloning objects in JavaScript**. It handles many edge cases that other methods struggle with, such as circular references, built-in types, and complex data structures. While it has so... | code_snippets | ||
d6ab212f-f986-40bf-bd69-e0a1d8785399 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/deep-clone-structured-clone.md | unknown | 97ed13ca-144d-4056-8cce-7cae948fafd5 | 5 | SemanticChunker@1.0.0 | 8c236ce8ea09d1aede3442bafaa77e1885e5d998df5cd4580f4f6c6f6013b29e | [Built-in types > Circular references]
### Circular references
`structuredClone()` **handles circular references out of the box**. `JSON.stringify()` throws and error, and most custom deep clones fail unless specifically designed for handling circular references.
```js
const obj = {};
obj.self = obj;
shallowClone(o... | unknown | unknown | [Built-in types > Circular references]
### Circular references
`structuredClone()` **handles circular references out of the box**. `JSON.stringify()` throws and error, and most custom deep clones fail unless specifically designed for handling circular references.
```js
const obj = {};
obj.self = obj;
shallowClone(o... | [Built-in types > Circular references]
### Circular references
`structuredClone()` **handles circular references out of the box**. `JSON.stringify()` throws and error, and most custom deep clones fail unless specifically designed for handling circular references.
```js
const obj = {};
obj.self = obj;
shallowClone(o... | code_snippets | ||
f07b8088-4a0d-4d60-ba60-0022b6de3ee8 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/deep-clone-structured-clone.md | unknown | 97ed13ca-144d-4056-8cce-7cae948fafd5 | 2 | SemanticChunker@1.0.0 | 22b37791250c4690703606b1e06709406b1e6a36be3a1cc6f6895f9838d0080c | [Cloning methods overview]
```
- `shallowClone` creates a **shallow copy** of the object, meaning nested objects are still references to the original.
- `deepClone` **recursively clones the object**, handling nested objects and arrays.
- `jsonClone` uses **`JSON.stringify()` and `JSON.parse()`** to create a deep clon... | unknown | unknown | [Cloning methods overview]
```
- `shallowClone` creates a **shallow copy** of the object, meaning nested objects are still references to the original.
- `deepClone` **recursively clones the object**, handling nested objects and arrays.
- `jsonClone` uses **`JSON.stringify()` and `JSON.parse()`** to create a deep clon... | [Cloning methods overview]
```
- `shallowClone` creates a **shallow copy** of the object, meaning nested objects are still references to the original.
- `deepClone` **recursively clones the object**, handling nested objects and arrays.
- `jsonClone` uses **`JSON.stringify()` and `JSON.parse()`** to create a deep clon... | code_snippets | ||
87be6b00-c3f6-4bfc-b0d9-6239ae576b25 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/element-is-visible-in-viewport.md | unknown | cb936fc8-a2ef-4178-822d-71915be6ff0d | 1 | SemanticChunker@1.0.0 | 5d32c2ed69b4831bbb68beb1a1cf5926f113079726788aee24053d1f15b94a93 | ```js
const elementIsVisibleInViewport = (el, partiallyVisible = false) => {
const { top, left, bottom, right } = el.getBoundingClientRect();
const { innerHeight, innerWidth } = window;
return partiallyVisible
? ((top > 0 && top < innerHeight) ||
(bottom > 0 && bottom < innerHeight)) &&
((left > 0 && left < inner... | unknown | unknown | ```js
const elementIsVisibleInViewport = (el, partiallyVisible = false) => {
const { top, left, bottom, right } = el.getBoundingClientRect();
const { innerHeight, innerWidth } = window;
return partiallyVisible
? ((top > 0 && top < innerHeight) ||
(bottom > 0 && bottom < innerHeight)) &&
((left > 0 && left < inner... | ```js
const elementIsVisibleInViewport = (el, partiallyVisible = false) => {
const { top, left, bottom, right } = el.getBoundingClientRect();
const { innerHeight, innerWidth } = window;
return partiallyVisible
? ((top > 0 && top < innerHeight) ||
(bottom > 0 && bottom < innerHeight)) &&
((left > 0 && left < inner... | code_snippets | ||
9bf08484-ed26-47ac-ba5e-b06f22a4ced8 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/element-is-visible-in-viewport.md | unknown | cb936fc8-a2ef-4178-822d-71915be6ff0d | 0 | SemanticChunker@1.0.0 | c25824772c7c598f19de4c92df772f58451130fd5f049d34e535ab3a72df4c0a | ---
title: Check if an element is visible in the viewport using JavaScript
shortTitle: Element is visible in viewport
language: javascript
tags: [browser]
cover: flower-portrait-1
excerpt: Learn how to check if an element is visible in the browser's viewport, using this simple technique.
listed: true
dateModified: 2024... | unknown | unknown | ---
title: Check if an element is visible in the viewport using JavaScript
shortTitle: Element is visible in viewport
language: javascript
tags: [browser]
cover: flower-portrait-1
excerpt: Learn how to check if an element is visible in the browser's viewport, using this simple technique.
listed: true
dateModified: 2024... | ---
title: Check if an element is visible in the viewport using JavaScript
shortTitle: Element is visible in viewport
language: javascript
tags: [browser]
cover: flower-portrait-1
excerpt: Learn how to check if an element is visible in the browser's viewport, using this simple technique.
listed: true
dateModified: 2024... | code_snippets | ||
a281e15d-a41b-4521-98cc-7f60eaa2899e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/element-from-point.md | unknown | e644643c-a925-413e-8852-8c651a45ab41 | 0 | SemanticChunker@1.0.0 | ad0d853dcab6ffb10eaabe8f00bb1e01cbd50f8080bcf3ca05e0aa9d377507a2 | ---
title: Element at a specific point on the page
shortTitle: Element at specific coordinates
language: javascript
tags: [browser]
cover: armchair-in-yellow
excerpt: Using `Document.elementFromPoint()` to easily get the element at a specific point on the page.
listed: true
dateModified: 2022-12-18
---
Figuring out wh... | unknown | unknown | ---
title: Element at a specific point on the page
shortTitle: Element at specific coordinates
language: javascript
tags: [browser]
cover: armchair-in-yellow
excerpt: Using `Document.elementFromPoint()` to easily get the element at a specific point on the page.
listed: true
dateModified: 2022-12-18
---
Figuring out wh... | ---
title: Element at a specific point on the page
shortTitle: Element at specific coordinates
language: javascript
tags: [browser]
cover: armchair-in-yellow
excerpt: Using `Document.elementFromPoint()` to easily get the element at a specific point on the page.
listed: true
dateModified: 2022-12-18
---
Figuring out wh... | code_snippets | ||
29ec10f3-4aff-4fad-b517-bf65f5216e2e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/dynamic-properties-are-slow.md | unknown | e55d0b47-1f73-4b85-be69-f895ac9d4b4e | 0 | SemanticChunker@1.0.0 | 8e6050786e55b8535186f27bd83a905c8099d148bcbb8aa694bfe4293e88a64f | ---
title: Optimize dynamically added object properties
shortTitle: Dynamically added property optimization
language: javascript
tags: [object,performance]
cover: hiking-balance
excerpt: Dynamically adding object properties can be pretty slow in some cases. Here's how to optimize it.
listed: true
dateModified: 2022-11-... | unknown | unknown | ---
title: Optimize dynamically added object properties
shortTitle: Dynamically added property optimization
language: javascript
tags: [object,performance]
cover: hiking-balance
excerpt: Dynamically adding object properties can be pretty slow in some cases. Here's how to optimize it.
listed: true
dateModified: 2022-11-... | ---
title: Optimize dynamically added object properties
shortTitle: Dynamically added property optimization
language: javascript
tags: [object,performance]
cover: hiking-balance
excerpt: Dynamically adding object properties can be pretty slow in some cases. Here's how to optimize it.
listed: true
dateModified: 2022-11-... | code_snippets | ||
8b086054-5e16-4a06-903e-6f95a52350b9 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/edit-url-params.md | unknown | 88fd5c4e-c4c9-4eb8-bb6d-8991d06570f6 | 0 | SemanticChunker@1.0.0 | 41997d2cefe496d0ef1c241786987ac805defcb795da0a3c2570297d28341d34 | ---
title: Edit URL Parameters in JavaScript
shortTitle: Edit URL Parameters
language: javascript
tags: [string]
cover: sofia-tram
excerpt: Avoid the naive approach and use a more robust method to edit URL parameters in JavaScript.
listed: true
dateModified: 2022-12-07
---
Editing the query string of a URL in JavaScri... | unknown | unknown | ---
title: Edit URL Parameters in JavaScript
shortTitle: Edit URL Parameters
language: javascript
tags: [string]
cover: sofia-tram
excerpt: Avoid the naive approach and use a more robust method to edit URL parameters in JavaScript.
listed: true
dateModified: 2022-12-07
---
Editing the query string of a URL in JavaScri... | ---
title: Edit URL Parameters in JavaScript
shortTitle: Edit URL Parameters
language: javascript
tags: [string]
cover: sofia-tram
excerpt: Avoid the naive approach and use a more robust method to edit URL parameters in JavaScript.
listed: true
dateModified: 2022-12-07
---
Editing the query string of a URL in JavaScri... | code_snippets | ||
3dfbaee8-01f3-43e4-955c-5b603b2c413a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/dynamic-getter-chain-proxy.md | unknown | 92d2264d-cc5f-4044-beef-ca51ff30ecd7 | 0 | SemanticChunker@1.0.0 | 22a2377826a09f61af0bd4a71a52f351a900a2cf6f5948bafadd702d7e4e8078 | ---
title: Chaining dynamic getters using the Proxy object
shortTitle: Dynamic getter chaining
language: javascript
tags: [proxy]
cover: colorful-rocks
excerpt: Using the Proxy object, we can create chainable dynamic getters for objects in JavaScript.
listed: true
dateModified: 2023-05-28
---
The dawn of ES6 brought a... | unknown | unknown | ---
title: Chaining dynamic getters using the Proxy object
shortTitle: Dynamic getter chaining
language: javascript
tags: [proxy]
cover: colorful-rocks
excerpt: Using the Proxy object, we can create chainable dynamic getters for objects in JavaScript.
listed: true
dateModified: 2023-05-28
---
The dawn of ES6 brought a... | ---
title: Chaining dynamic getters using the Proxy object
shortTitle: Dynamic getter chaining
language: javascript
tags: [proxy]
cover: colorful-rocks
excerpt: Using the Proxy object, we can create chainable dynamic getters for objects in JavaScript.
listed: true
dateModified: 2023-05-28
---
The dawn of ES6 brought a... | code_snippets | ||
89e3624a-d85c-487e-987d-9ffc0e185c6d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/dynamic-getter-chain-proxy.md | unknown | 92d2264d-cc5f-4044-beef-ca51ff30ecd7 | 1 | SemanticChunker@1.0.0 | af3145d0218ac574cef73e51edab5253abf17f25051dd3101dee35d65366a02f | ```js
const getHandler = {
get: (target, prop) => {
return value => {
if (typeof value !== 'undefined') {
target[prop] = value;
return new Proxy(target, getHandler);
}
return target[prop];
};
}
};
const styles = {};
const proxiedStyles = new Proxy(styles, getHandler);
proxiedStyles.color('#101010').backgroun... | unknown | unknown | ```js
const getHandler = {
get: (target, prop) => {
return value => {
if (typeof value !== 'undefined') {
target[prop] = value;
return new Proxy(target, getHandler);
}
return target[prop];
};
}
};
const styles = {};
const proxiedStyles = new Proxy(styles, getHandler);
proxiedStyles.color('#101010').backgroun... | ```js
const getHandler = {
get: (target, prop) => {
return value => {
if (typeof value !== 'undefined') {
target[prop] = value;
return new Proxy(target, getHandler);
}
return target[prop];
};
}
};
const styles = {};
const proxiedStyles = new Proxy(styles, getHandler);
proxiedStyles.color('#101010').backgroun... | code_snippets | ||
ebd9dd9f-8787-4b02-98c0-fcacffc71540 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/double-negation-operator.md | unknown | 13584c1d-6e91-40b6-a406-d93386ffc11b | 0 | SemanticChunker@1.0.0 | 5756e1f6243adff044df1e36cc5d4aa69331b86d31bfcee8581605096e73dedd | ---
title: What does the double negation operator do in JavaScript?
shortTitle: Double negation operator
language: javascript
tags: [type]
cover: memories-of-pineapple-2
excerpt: You've probably come across the double negation operator (`!!`) before, but do you know what it does?
listed: true
dateModified: 2022-07-26
-... | unknown | unknown | ---
title: What does the double negation operator do in JavaScript?
shortTitle: Double negation operator
language: javascript
tags: [type]
cover: memories-of-pineapple-2
excerpt: You've probably come across the double negation operator (`!!`) before, but do you know what it does?
listed: true
dateModified: 2022-07-26
-... | ---
title: What does the double negation operator do in JavaScript?
shortTitle: Double negation operator
language: javascript
tags: [type]
cover: memories-of-pineapple-2
excerpt: You've probably come across the double negation operator (`!!`) before, but do you know what it does?
listed: true
dateModified: 2022-07-26
-... | code_snippets | ||
07357dc3-18b2-4123-8082-600f7ff65bc1 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/dynamic-getter-setter-proxy.md | unknown | 3c40c195-a223-44ba-8bdd-47276384ec76 | 2 | SemanticChunker@1.0.0 | b6e6329cbc48e4f9e0f5f27f330de4522d37fbf55dbc1a9a80969d1003028574 | [Dynamic getters > Dynamic setters]
## Dynamic setters
A **dynamic setter** is a setter that is not explicitly defined for a property, but is instead created on the fly when the property is set. This can be very useful if the object's keys follow a certain pattern or certain conditions apply to all values that are se... | unknown | unknown | [Dynamic getters > Dynamic setters]
## Dynamic setters
A **dynamic setter** is a setter that is not explicitly defined for a property, but is instead created on the fly when the property is set. This can be very useful if the object's keys follow a certain pattern or certain conditions apply to all values that are se... | [Dynamic getters > Dynamic setters]
## Dynamic setters
A **dynamic setter** is a setter that is not explicitly defined for a property, but is instead created on the fly when the property is set. This can be very useful if the object's keys follow a certain pattern or certain conditions apply to all values that are se... | code_snippets | ||
2cbce609-ffbf-4438-bbeb-4b8cd219f7ef | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/dynamic-getter-setter-proxy.md | unknown | 3c40c195-a223-44ba-8bdd-47276384ec76 | 1 | SemanticChunker@1.0.0 | 3e775313987a1b8b0117905e6894ef9dcd4c3f30342061236bf2a891c74c4084 | [Dynamic getters]
## Dynamic getters
A **dynamic getter** is a getter that is not explicitly defined for a property, but is instead created on the fly when the property is accessed. This is particularly useful when the shape of the data is not known in advance, or when the value of a property needs to be manipulated ... | unknown | unknown | [Dynamic getters]
## Dynamic getters
A **dynamic getter** is a getter that is not explicitly defined for a property, but is instead created on the fly when the property is accessed. This is particularly useful when the shape of the data is not known in advance, or when the value of a property needs to be manipulated ... | [Dynamic getters]
## Dynamic getters
A **dynamic getter** is a getter that is not explicitly defined for a property, but is instead created on the fly when the property is accessed. This is particularly useful when the shape of the data is not known in advance, or when the value of a property needs to be manipulated ... | code_snippets | ||
aea5ecee-9fce-40bb-9d61-38969dc6e202 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/dynamic-getter-setter-proxy.md | unknown | 3c40c195-a223-44ba-8bdd-47276384ec76 | 3 | SemanticChunker@1.0.0 | 3b10fd700c44b1f4070ea09ea29388b3548bec73cc61f384d80e2f825aa65c98 | [Dynamic getters > Conclusion]
## Conclusion
As shown in this post, the `Proxy` object provides a particularly powerful way to manipulate the behavior of objects. That being said, you might want to consider your specific use-case before reaching for this tool. Dynamic getters and setters can be very useful, but they ... | unknown | unknown | [Dynamic getters > Conclusion]
## Conclusion
As shown in this post, the `Proxy` object provides a particularly powerful way to manipulate the behavior of objects. That being said, you might want to consider your specific use-case before reaching for this tool. Dynamic getters and setters can be very useful, but they ... | [Dynamic getters > Conclusion]
## Conclusion
As shown in this post, the `Proxy` object provides a particularly powerful way to manipulate the behavior of objects. That being said, you might want to consider your specific use-case before reaching for this tool. Dynamic getters and setters can be very useful, but they ... | code_snippets | ||
fb2a1ae4-129c-48f5-ae5c-ca8a0eb10494 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/dynamic-getter-setter-proxy.md | unknown | 3c40c195-a223-44ba-8bdd-47276384ec76 | 0 | SemanticChunker@1.0.0 | 3b6692b1aea99db623bef72486feb9d8f628ae07dd7d84b4b89e7587e3f1831f | ---
title: Can I create dynamic setters and getters in JavaScript?
shortTitle: Dynamic getters and setters
language: javascript
tags: [proxy]
cover: green-cabin-cow
excerpt: Using the Proxy object, we can create dynamic getters and setters for objects in JavaScript.
listed: true
dateModified: 2023-04-09
---
Sometimes,... | unknown | unknown | ---
title: Can I create dynamic setters and getters in JavaScript?
shortTitle: Dynamic getters and setters
language: javascript
tags: [proxy]
cover: green-cabin-cow
excerpt: Using the Proxy object, we can create dynamic getters and setters for objects in JavaScript.
listed: true
dateModified: 2023-04-09
---
Sometimes,... | ---
title: Can I create dynamic setters and getters in JavaScript?
shortTitle: Dynamic getters and setters
language: javascript
tags: [proxy]
cover: green-cabin-cow
excerpt: Using the Proxy object, we can create dynamic getters and setters for objects in JavaScript.
listed: true
dateModified: 2023-04-09
---
Sometimes,... | code_snippets | ||
15adccbc-85d4-47df-abde-3ba5ce54d5c8 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/empty-array-every-some.md | unknown | 5af3b9a0-6bf6-474e-bb4b-6042658f7a20 | 2 | SemanticChunker@1.0.0 | 55b74b03f3ab4ab49b44cd19c7dc19fb117fa42a907e1cfb26823d417d47e539 | [The documentation explanation > A developer's approach]
## A developer's approach
As you may be able to tell at this point, I wasn't satisfied with the official answer. I felt that, intuitively, the result wasn't wrong, but the explanation was lacking. Thinking on this problem, I thought to implement the code myself... | unknown | unknown | [The documentation explanation > A developer's approach]
## A developer's approach
As you may be able to tell at this point, I wasn't satisfied with the official answer. I felt that, intuitively, the result wasn't wrong, but the explanation was lacking. Thinking on this problem, I thought to implement the code myself... | [The documentation explanation > A developer's approach]
## A developer's approach
As you may be able to tell at this point, I wasn't satisfied with the official answer. I felt that, intuitively, the result wasn't wrong, but the explanation was lacking. Thinking on this problem, I thought to implement the code myself... | code_snippets | ||
2a7dc415-cbdd-49d7-b5dc-0e7ff71f924b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/empty-array-every-some.md | unknown | 5af3b9a0-6bf6-474e-bb4b-6042658f7a20 | 3 | SemanticChunker@1.0.0 | 815708d9cec7647ae28de6abca062b5ba28ddf7ecc070966ddbe2a78cf79f81e | [A developer's approach > Iterating over empty arrays]
### Iterating over empty arrays
Imagine that you have an array with any number of elements and a predicate function that will result in either `true` or `false`. When you call `Array.prototype.every()` on this array, the method will **iterate over each element** ... | unknown | unknown | [A developer's approach > Iterating over empty arrays]
### Iterating over empty arrays
Imagine that you have an array with any number of elements and a predicate function that will result in either `true` or `false`. When you call `Array.prototype.every()` on this array, the method will **iterate over each element** ... | [A developer's approach > Iterating over empty arrays]
### Iterating over empty arrays
Imagine that you have an array with any number of elements and a predicate function that will result in either `true` or `false`. When you call `Array.prototype.every()` on this array, the method will **iterate over each element** ... | code_snippets | ||
48d7c21b-0a1a-48a0-bac5-170ddbdcaf7d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/empty-array-every-some.md | unknown | 5af3b9a0-6bf6-474e-bb4b-6042658f7a20 | 4 | SemanticChunker@1.0.0 | 6698117ccafc1f65eb7b56f45eb5060b7868ad1b9510a08706d7fe349e0fa6c9 | [A developer's approach > A `for` loop analogy]
### A `for` loop analogy
If you think about it in terms of a `for` loop, it makes a little more sense:
```js {4}
const every = (arr, predicate) => {
for (let val in arr)
if (!predicate(val[i])) return false;
return true;
};
every([], () => false); // true
```
As ... | unknown | unknown | [A developer's approach > A `for` loop analogy]
### A `for` loop analogy
If you think about it in terms of a `for` loop, it makes a little more sense:
```js {4}
const every = (arr, predicate) => {
for (let val in arr)
if (!predicate(val[i])) return false;
return true;
};
every([], () => false); // true
```
As ... | [A developer's approach > A `for` loop analogy]
### A `for` loop analogy
If you think about it in terms of a `for` loop, it makes a little more sense:
```js {4}
const every = (arr, predicate) => {
for (let val in arr)
if (!predicate(val[i])) return false;
return true;
};
every([], () => false); // true
```
As ... | code_snippets | ||
93fc2036-c959-4554-9bef-8cc7dc9e1d10 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/empty-array-every-some.md | unknown | 5af3b9a0-6bf6-474e-bb4b-6042658f7a20 | 5 | SemanticChunker@1.0.0 | 9f220067516d196b6265558241a48f827d33bbe328f2e27f743c0df21a8a69e2 | [The documentation explanation > Conclusion]
## Conclusion
After some digging, it makes sense that `Array.prototype.every()` returns `true` when called on an empty array. While described explicitly in both the ECMAScript specification and the MDN documentation, the explanation might not seem intuitive at first, but d... | unknown | unknown | [The documentation explanation > Conclusion]
## Conclusion
After some digging, it makes sense that `Array.prototype.every()` returns `true` when called on an empty array. While described explicitly in both the ECMAScript specification and the MDN documentation, the explanation might not seem intuitive at first, but d... | [The documentation explanation > Conclusion]
## Conclusion
After some digging, it makes sense that `Array.prototype.every()` returns `true` when called on an empty array. While described explicitly in both the ECMAScript specification and the MDN documentation, the explanation might not seem intuitive at first, but d... | code_snippets | ||
a678c16f-81ac-4476-aae2-5169a9d9bbe6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/empty-array-every-some.md | unknown | 5af3b9a0-6bf6-474e-bb4b-6042658f7a20 | 1 | SemanticChunker@1.0.0 | c5a87503ed6aea1aa768023b94c42f00532bfb6687406407b2c2c33dc668a451 | [The documentation explanation]
## The documentation explanation
The **official MDN documentation**, that is linked above, states the following in regards to this scenario:
> `every` acts like the "for all" quantifier in mathematics. In particular, for an empty array, it returns `true`. (It is [vacuously true](https... | unknown | unknown | [The documentation explanation]
## The documentation explanation
The **official MDN documentation**, that is linked above, states the following in regards to this scenario:
> `every` acts like the "for all" quantifier in mathematics. In particular, for an empty array, it returns `true`. (It is [vacuously true](https... | [The documentation explanation]
## The documentation explanation
The **official MDN documentation**, that is linked above, states the following in regards to this scenario:
> `every` acts like the "for all" quantifier in mathematics. In particular, for an empty array, it returns `true`. (It is [vacuously true](https... | code_snippets | ||
f2a50a26-c4aa-4757-9eff-5fb6613eeef6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/empty-array-every-some.md | unknown | 5af3b9a0-6bf6-474e-bb4b-6042658f7a20 | 0 | SemanticChunker@1.0.0 | a10662500439fd93782ba6802233dd7e9d2d5ccdb53ff1f88c12d97f47a5a34a | ---
title: What happens when you call every() on an empty JavaScript array?
shortTitle: Empty array every()
language: javascript
tags: [array]
cover: blue-bird
excerpt: A few days ago, I stumbled upon a perplexing piece of JavaScript behavior. Let's break it down.
listed: true
dateModified: 2025-03-14
---
A few days a... | unknown | unknown | ---
title: What happens when you call every() on an empty JavaScript array?
shortTitle: Empty array every()
language: javascript
tags: [array]
cover: blue-bird
excerpt: A few days ago, I stumbled upon a perplexing piece of JavaScript behavior. Let's break it down.
listed: true
dateModified: 2025-03-14
---
A few days a... | ---
title: What happens when you call every() on an empty JavaScript array?
shortTitle: Empty array every()
language: javascript
tags: [array]
cover: blue-bird
excerpt: A few days ago, I stumbled upon a perplexing piece of JavaScript behavior. Let's break it down.
listed: true
dateModified: 2025-03-14
---
A few days a... | code_snippets | ||
222658ad-3b07-4084-b582-c955a2c4e311 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/email-validation.md | unknown | 04d0f44a-1162-4c27-b22e-b262de68c3c7 | 0 | SemanticChunker@1.0.0 | abd0c926635954b33a70ade1dbfd79a12a71bdfdd16731cd9c8856000d445afd | ---
title: Can I validate an email address in JavaScript?
shortTitle: Email address validation
language: javascript
tags: [string,regexp]
cover: blank-card
excerpt: Email address validation can be much trickier than it sounds. Here's why and my advice on how to approach this problem.
listed: true
dateModified: 2022-10-... | unknown | unknown | ---
title: Can I validate an email address in JavaScript?
shortTitle: Email address validation
language: javascript
tags: [string,regexp]
cover: blank-card
excerpt: Email address validation can be much trickier than it sounds. Here's why and my advice on how to approach this problem.
listed: true
dateModified: 2022-10-... | ---
title: Can I validate an email address in JavaScript?
shortTitle: Email address validation
language: javascript
tags: [string,regexp]
cover: blank-card
excerpt: Email address validation can be much trickier than it sounds. Here's why and my advice on how to approach this problem.
listed: true
dateModified: 2022-10-... | code_snippets | ||
d36036a0-3fb2-41fe-aa75-53ffe5fe9aa1 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/email-validation.md | unknown | 04d0f44a-1162-4c27-b22e-b262de68c3c7 | 1 | SemanticChunker@1.0.0 | e9150bab1e1eb560615293f6c2a0f227d0f1527dbda747ef52e2e09be60e4186 | By now, you should be starting to figure out why I've been hesitant to showcase a solution to the problem of email validation. While solutions do exist, the implications of each one must be considered carefully.
My suggestion would be to **check for basic structural elements** on the frontend, then **send a confirmati... | unknown | unknown | By now, you should be starting to figure out why I've been hesitant to showcase a solution to the problem of email validation. While solutions do exist, the implications of each one must be considered carefully.
My suggestion would be to **check for basic structural elements** on the frontend, then **send a confirmati... | By now, you should be starting to figure out why I've been hesitant to showcase a solution to the problem of email validation. While solutions do exist, the implications of each one must be considered carefully.
My suggestion would be to **check for basic structural elements** on the frontend, then **send a confirmati... | code_snippets | ||
981d3f14-c82a-4441-896c-d2c89551db06 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/divmod.md | unknown | 35ae441e-68b9-4a35-a536-c4c45ae7c4cf | 0 | SemanticChunker@1.0.0 | a5054a1bc699838bba5fd5e3b2fa727c9cebef25930bf5725b95afadc94bc0a4 | ---
title: Calculate the quotient and remainder of a division in JavaScript
shortTitle: Quotient and remainder of division
language: javascript
tags: [math]
cover: italian-horizon
excerpt: Implement Python's `divmod()` built-in function in one line of JavaScript.
listed: true
dateModified: 2023-12-28
---
Python's [`di... | unknown | unknown | ---
title: Calculate the quotient and remainder of a division in JavaScript
shortTitle: Quotient and remainder of division
language: javascript
tags: [math]
cover: italian-horizon
excerpt: Implement Python's `divmod()` built-in function in one line of JavaScript.
listed: true
dateModified: 2023-12-28
---
Python's [`di... | ---
title: Calculate the quotient and remainder of a division in JavaScript
shortTitle: Quotient and remainder of division
language: javascript
tags: [math]
cover: italian-horizon
excerpt: Implement Python's `divmod()` built-in function in one line of JavaScript.
listed: true
dateModified: 2023-12-28
---
Python's [`di... | code_snippets | ||
0f749442-b04e-4faf-9dd6-3cd093e1f4a3 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/euclidean-distance.md | unknown | 984ca5be-421c-485d-8fa0-171675a2b45e | 2 | SemanticChunker@1.0.0 | 274de749381f36e0db19c6533d2c3ec8d701afb6cb8c645937b3d3e66e05117c | [Definition > Implementation]
## Implementation
JavaScript's `Math.hypot()` method can be used to calculate the Euclidean distance between two points in **2 dimensions**.
```js
const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
distance(1, 1, 2, 3); // ~2.2361
```
In **3 dimensions**, the formula i... | unknown | unknown | [Definition > Implementation]
## Implementation
JavaScript's `Math.hypot()` method can be used to calculate the Euclidean distance between two points in **2 dimensions**.
```js
const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
distance(1, 1, 2, 3); // ~2.2361
```
In **3 dimensions**, the formula i... | [Definition > Implementation]
## Implementation
JavaScript's `Math.hypot()` method can be used to calculate the Euclidean distance between two points in **2 dimensions**.
```js
const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
distance(1, 1, 2, 3); // ~2.2361
```
In **3 dimensions**, the formula i... | code_snippets | ||
2b10c209-f2c2-433f-b960-597f083501c9 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/euclidean-distance.md | unknown | 984ca5be-421c-485d-8fa0-171675a2b45e | 1 | SemanticChunker@1.0.0 | 6bb18ee97343399c20460d8ce2ae3f790181f96473924fb9d22133af639d6a7b | [Definition]
## Definition
The [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance) between two points is the **length of the line segment connecting them**. The formula for calculating it in 2D is equal to the **hypotenuse** of a right triangle, given by the [Pythagorean theorem](https://en.wikiped... | unknown | unknown | [Definition]
## Definition
The [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance) between two points is the **length of the line segment connecting them**. The formula for calculating it in 2D is equal to the **hypotenuse** of a right triangle, given by the [Pythagorean theorem](https://en.wikiped... | [Definition]
## Definition
The [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance) between two points is the **length of the line segment connecting them**. The formula for calculating it in 2D is equal to the **hypotenuse** of a right triangle, given by the [Pythagorean theorem](https://en.wikiped... | code_snippets |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.