HTML and CSS Reference
In-Depth Information
Yet, there isn't a good way to modify arrays in JavaScript without creating newly allocated objects on the heap.
You can do some things to mitigate this, and, to that end, a great resource is Static Memory JavaScript with Object
Pools ( www.html5rocks.com/en/tutorials/speed/static-mem-pools/ ) . Unfortunately, it won't completely solve
your problems, but keeping these performance considerations in mind will go a long way toward mitigating your
biggest memory performance issues.
null
The null type is a special value similar to None in Python. null signifies when a value has been emptied or specifically
set to nothing. Note that this is distinct from the value that unknown variables are equal to or that declared but
unassigned variables are set to. For that, we have undefined .
undefined
Variables are initially set to undefined when declared. Remember from declaration hoisting that declarations are
automatically hoisted to the top of the function but that any accompanying assignments are not. This means that
any variables will be set to undefined between where they're declared at the top of a function and where they're
assigned to.
Let's take a look at the difference between undefined and null:
var player = {
health: 100,
damage: 5,
hit: function() {
console.log('poke');
}
};
console.log(enemy);
var enemy = {
health: 100,
damage: 50,
hit: function() {
console.log('SMASH');
}
};
console.log(enemy.health);
console.log(player.shields);
This code will output as follows:
> undefined
> 100
> undefined
 
Search WWH ::




Custom Search