JavaScript Array, Stack, Queue - what is the motivation for this particular API design?

In my daily work, I mainly use C # and sometimes use javascript, so please, javascript Gurus, do not judge my questions rudely!

  • The array implements Stack by providing methods push, pop but is peekmissing, why? (yes, trivial to implement, but still)
  • An array implements a queue, but operations are called push- shiftor unshift- popinstead of, enqueueand dequeuewhy name them differently? Is it inspired by Python and Ruby?
  • Why are the APIs for the array, stack and queue combined into one object instead of separating the interface and having different objects for this? Is it because the implementation is cheap?
  • Semantically in many languages ​​(C #, C ++, Java), an array is a continuous block in memory and is not re-significant. On the other hand, a basic collection that allows you to easily add items is a List (ArrayList or LinkedList or the like). Wouldn't it be better if Array were named List in javascript?
  • How is Array implemented under the hood? Where can I find a very detailed description?
+6
source share
1 answer
  • JavaScript was invented after 10 days, peek was never added, because, mainly because it is easy to implement, perhaps one day.

  • Unlike what you know, yes

  • This is a high-level programming language, also check typed arrays

  • , .

  • Engine, Python

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

+1

Source: https://habr.com/ru/post/1017056/


All Articles