Use cases for parentheses, braces, brackets and quotes JavaScript in language

parentheses()

Use cases
  1. Provide arguments for function declaration, e.g.: function doSomething (how, when) {}
  2. Execute function, e.g.: var result = doSomething()
  3. Execute function with parameters, e.g.: doSomething(nice)
  4. Provide conditional statements conditions, for example loop, if, and switch statements, e.g.: while (var < 0) {do something}
  5. Provide switch statement conditions, e.g.:
    switch (bestFoods) {
    case "pizza":
    console.log("get it");
    case ...
  6. Execute Immediately Invoked Function Expressions (IIFE), e.g.:
    (function () {
    var shout = "I'm alive!";
    alert (shout);
    }) ();

brackets[]

Use cases
  1. Creating arrays, e.g.: myArray = [element1, element2, element3]
  2. Accessing array elements by their index, e.g. myArray = ["cat", "dog", "mouse"]
    console.log(myArray[0]);
  3. Accessing and updating properties of objects, especially if the property name has a space or different not-allowed sign in the name, e.g. cat.enemies["too-much water"]
    myObject["some name"]="newName"

braces{}

Use cases
  1. Creating objects, e.g.:
    var objectCat = {
    "name": "Cat",
    "legs": 4,
    "enemies": ["dogs", "water"]}
  2. Creating conditional statements, e.g.: if (conditions) {statement body};
  3. Initialising functions, e.g.: function myFunction () {function body};

single quotes ''

Use cases
  1. Accessing object properties with bracket notation, e.g. objectCat['name']
  2. String literals, e.g. var shout = 'I'm alive'

double quotes ""

Use cases
  1. Same as single quotes, plus:
  2. Use to create objects with string elements, e.g.: var myObjectDinner = {"soft drink", "salad", "fish"} (JSON strings must be double quoted source)
  3. Single and double quotes next to each other are not allowed in JS, hence the following code: 'Quoth the raven:\n\t\"Nevermore!\"'
    to produce the following string:
    Quoth the raven:
          "Nevermore!"
↑