---
title: "Discussion on \"Heaps in JavaScript\" | Hashnode"
description: "Discussion on \"Heaps in JavaScript\". So far we've looked at implementation of tree data structure and some of it's variants such as trie. In this post, we'll dive into heaps. These are also referred to as priority queues.\nIntroduction\nHeap is a variant of tree data structure, with two a..."
url: "https://hashnode.com/posts/heaps-in-javascript/617fef0ff597ba4a82795f31"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Heaps in JavaScript](https://stackfull.dev/heaps-in-javascript?utm_source=hashnode&utm_medium=feed)

So far we've looked at implementation of tree data structure and some of it's variants such as trie. In this post, we'll dive into heaps. These are also referred to as priority queues. Introduction Heap is a variant of tree data structure, with two a...

Nov 1, 2021 · 10 min read · stackfull.dev  
Updated Apr 24, 2025  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#algorithms](https://hashnode.com/tag/algorithms)
-   [#data-structures](https://hashnode.com/tag/data-structures)
-   [#interview](https://hashnode.com/tag/interview)
-   [#frontend-development](https://hashnode.com/tag/frontend-development)

## Written by

[Anish Kumar](https://hashnode.com/@akumar)

@akumar

  
[View profile](https://hashnode.com/@akumar)

## Responses 3

Markdown supported · ⌘↵ to post

[gr](https://hashnode.com/@brodiegander)

[Oct 20, 2023](https://hashnode.com/posts/heaps-in-javascript/617fef0ff597ba4a82795f31/comment/6532c3f4c122764cb539e80d)

Thanks for this amazing writeup!

[V K](https://hashnode.com/@doncorleone)

[Oct 5, 2023](https://hashnode.com/posts/heaps-in-javascript/617fef0ff597ba4a82795f31/comment/651ef0f37e37d3b346c61f0e)

percolateDown function is exactly same as heappop. This won't create a heap of out an array. If the initial array is \[3,5,4,10,2,1\]. After percolateDown's execution array will be \[3,2,1,10,5,4\] which is still not a heap. Edit: for some one looking at it in future. In heapify function, instead of running from first node to last. It should run from last to first so (let i = last;i>=0;i--)

[Krzysztof Witkowski](https://hashnode.com/@kriskw1999)

[Jul 14, 2024](https://hashnode.com/posts/heaps-in-javascript/617fef0ff597ba4a82795f31/comment/651ef0f37e37d3b346c61f0e#reply-669387ee651e88d1ba647e51)

I was wondering exactly the same thing reading this function. Thanks for confirming my doubts!

[Shinu Raju](https://hashnode.com/@Shinu786)

[Aug 20, 2023](https://hashnode.com/posts/heaps-in-javascript/617fef0ff597ba4a82795f31/comment/64e283cfa9a8b9bbc8cf69e5)

Well explained
