Javascript Definitions
💻Programming Language
javascript
definitions
strict mode
-
Add the following line at the beginning of your script!
'use strict'; - More information: JavaScript Use Strict
with
In the following example Math is added to the top of the scope chain and thus you don’t have to write Math.PI.
var a, x, y;
var r = 10;
with (Math) {
a = PI * r * r;
x = r * cos(PI);
y = r * sin(PI / 2);
}see with statement documentation.
Literal vs. Object
-
Array Literal
['eat', 'bananas']; -
Array Object
new Array('eat', 'bananas');
rest vs. spread operator ...
restoperator gives you rest of input arguments as array. Should always occur at end of the list.spreadoperator splits array into single arguments for a function.
… spread operator documentation
bind()
Example from MDN:
In bind(context, [variable1, variable2, ...]) the context will be bound as this to the newly created bound function.
this.x = 9;
var module = {
x: 81,
getX: function () {
return this.x;
},
};
module.getX(); // 81
var retrieveX = module.getX;
retrieveX();
// returns 9. The function gets invoked at the global scope.
// Create a new function with 'this' bound to module
// New programmers might confuse the
// global var x with module's property x
var boundGetX = retrieveX.bind(module);
boundGetX(); // 81call(), apply()
UNDERCONSTRUCTION_
apply()
Call function with certain value set as this value
ASI - Automatic semicolon insertion
See this SO thread and how prettier deals with it.
Dynamic typing
- Dynamic typing (JS) vs. static typing (TS)
Discuss on Twitter ● Improve this article: Edit on GitHub