A re-introduction to JavaScript - MDC
developer.mozilla.org
developer.mozilla.org
I know you can print things out and bind them but it's just not the same.
I found an error:
switch(1 + 3):
case 2 + 2:
yay();
break;
default:
neverhappens();
}
The ":" after the first line should be a "{".let is not useful to anyone doing browser based javascript work, because it doesn't work in any browser other than Firefox and derivatives. Getting a slightly different scope behavior is hardly worth throwing out 70-80% of potential users.
>>> var test={foo:123}
>>> test.foo = undefined
>>> for (var i in test) { console.log(i); }
foo
>>> delete test.foo
true
>>> for (var i in test) { console.log(i); }JavaScript is a garbage collected language. As such, you, the developer, have no control over when an object can be ejected from memory. When a reference to your object no longer exists, it can be considered for collection. Until then, it can't.
In your example, the number object (123) is eligible for collection in both cases. The difference has nothing to do with 123, but instead relates to the test object.
In the first case, test will still have a foo property, which won't point to anything. In the second case, the property itself will be removed from the test object.
It's (most likely) true that leaving the foo property intact means using more memory than if you delete it, but the memory used is less than actual object, and whether or not this qualifies as a leak is debatable. Which leaves my original statement:
delete's only purpose is to remove a property name from an object
This is particularly relevant when you iterate over the keys in an object for some reason. In the case of a global variable, this is just an implicit removal from the global/window object.