Javascript compiles this code without error:
function test() {
property: true;
alert('testing');
}
test(); // Shows message 'testing'
alert(test.property); // Shows 'undefined'
Is the content of property accessible in any way?
If not, what is the purpose of accepting this code?
propertyis not a property here. It’s a label– something you could use withbreakorcontinue. You could reformat the code you have like this:You’re not actually referencing the label, and the thing that comes after it (true) is just a no-op statement, so nothing happens when it executes. The function only meaningfully contains an alert statement.
You seem to be confusing an object literal with a function definition. You could create an object with properties like this:
You might also be confusing it with a couple other patterns. Let us know what you’re trying to accomplish for more info.