Who uses underscore js

Javascript designations / identifiers

Javascript Identifier

Names or identifiers of variables, methods, functions ... must begin with a small or capital letter, an underscore or a $ sign. This can be followed by the digits from 0 to 9. Hyphens (-) in names are not allowed and lead to a syntax error: Unexpected token '-'.

Valid names of variables, methods or functions are e.g.

const value = 42; function Value123 () {} let result = [18,19,20];

Identifiers must not begin with a number. On the other hand is _2Demo a valid identifier (see $ and Underscore).

Javascript is case-sensitive - sensitive to upper and lower case. Surname and Surname are two different variable names.

Javascript $ sign

Javascript treats $ and _ in the same way as the other letters of the alphabet.

The dollar sign is a shorthand for the document.getElementById () function in many libraries, because this method is often used, but it is a long tapeworm of characters that makes the code cluttered.

Out

"capture-" + document.getElementById ("canvas"). width + "x" + document.getElementById ("canvas"). height + ".png"

becomes

function $ (x) {return document.getElementById (x); } "capture - $ {canvas.width} x $ {canvas.height} .png"

The underscore _

Prefixing a name with the underscore is a common convention that refers to a property of the object or method as a private indicates.

This convention is particularly useful in Javascript because fields are written without the private and public keywords.

Just like the $ sign, the underscore is just a convention - from the JavaScript point of view, $ and _ in the script code are just simple letters of the alphabet. In data, however, they are special characters.

Keywords - reserved keywords

Reserved keywords cannot be used as variable names - e.g. break or boolean. If that were all ... keywords are not allowed any longer

  • as a name in a literal object notation
  • as a member's name in dot notation
  • as an argument of a function
  • as a variable
  • as an unqualified global variable
  • as a jump label

to be used.

Reserved words

abstractbooleanbreakbytecasecatchcharclassconstcontinuedebuggerdefaultdeletedodoubleelseenumexportextendsfalsefinalfinallyfloatforfunctiongotoifimplementsimportininstanceofintinterfacelongletnativeewnullpackageprivateprotectedoftranswitchedvariousshortrowaticsthypeupersewhilistofrequotated

Not all reserved words are actually used in JavaScript. As a precaution, they will be switched off for possible use in a later JavaScript version.

External sources