Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 04/09/2018 in all areas

  1. The OR operator in Javascript returns the leftmost operand that evaluates to a boolean true value. In the following code, the variable x gets set to 5 because 0 is false. var x = 0 || 5; When you assign a variable to itself nothing changes: var x = x; When a variable does not exist, its value is undefined which evaluates to boolean false. In the following code the variable x gets set to 5 because an undefined variable is false. var x = x || 5; In conclusion, the code var x = x || []; will do nothing when x already exists but will assign an empty array to x if it does not already exist. The reason that people creating embeddable scripts do this is to prevent the program from breaking when somebody embeds their code more than once in the same document.
    1 point
  2. In the first example, if you change a, b will also change because they're both pointing to the same thing. In the second example, both a and b can be changed independently of each other because they're two different arrays that merely have identical content.
    1 point
×
×
  • Create New...