-2

I've learned python and right now I am beginning to learn javascript. I've got a question about Javascript objects.

var superSecureTerminal = {
        allUserNames: [],
        _username: "",
        ...}

Are the allUserNames and _username arguments of the object? In python would it be similar to

def superSecureTerminal(allUserNames, _username):

BBB_TOAD
  • 49
  • 7
  • 2
    No, objects do not have arguments, only properties. A function is quite distinct from an object – CertainPerformance Aug 10 '22 at 22:25
  • ...but JS objects themselve can be arguments to JS functions - and a recently-added feature of JS is auto-destructuring objects to parameters: https://stackoverflow.com/questions/37661166/what-do-curly-braces-inside-of-function-parameter-lists-do-in-es6 – Dai Aug 10 '22 at 22:26
  • 1
    A javascript object is like a python dictionary. – Rocky Sims Aug 10 '22 at 22:28
  • The Python code would be almost identical to the JS code, except without the `var` keyword. And you need to quote the dictionary keys in Python. – Barmar Aug 10 '22 at 22:30

1 Answers1

1

JS objects are most like Python dictionaries. That JS code is equivalent to the Python

superSecureTerminal = {
    "allUserNames": [],
    "_username": "",
    ...
}

However, JS objects also have prototypes that can be used like classes are used in Python. EcmaScript 6 added class declarations that create the prototypes automatically, so the code can be organized similarly to the way you write classes in Python and PHP.

Barmar
  • 741,623
  • 53
  • 500
  • 612