User:Valento/JSThingies

From Guild Wars 2 Wiki
Jump to navigationJump to search

Some notes as I run into "unexpected" things (most likely how the language itself works).

  • Comparing a string to a single-item array
var test = ['mystring'];
test==='mystring' // equals (either == or ===) true, test[0] outputs 'mystring' aswell, if number of elements increase it results false
  • Dot notation for object keys
var myojb = {'first': 'st', 'second': 'nd', 'third': 'rd'};
myobj.first // equals 'st', if key is a number it must use array-like notation myobj['1432]
  • Non-capture group for regexs
(?:#([0-9]+)) // yields $1 (an infinite integer) while matching something like "#999", outer capture group is not captured; this is said to be ugly though