Javascript anonymous functions expressions

Hello everybody!
I came across this code in a javascript book:

object123.onload = function() {
    // Code
}

I would like to ask: is this a function expression much like assigning a function expression to a variable, like this:

var xyz = function () {
    // Code
};

and if it is a function expression, why is there no semicolon after the final curly braces?
Any help would be greatly appreciated.
thanks in advance.

Yes exactly – just instead of to a variable, you’re assigning it to an object property, and the function becomes a method of that object.

Apparently the author just forgot it… if you’re using semicolons throughout, there would have to be one too. It’s not necessary here either though because of the automatic semicolon insertion (ASI).

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.