It’s perfectly valid.
You wouldn’t want to put great big blocks of code mixed up in the markup there (better to use external scripts), but it can be useful to:
-
add extra binding information for progressive-enhancement (where that data is difficult to fit into a classname or other approach to hiding extended information in attributes); or
-
where it’s necessary to kick off a scripted enhancement as quickly as possible (rather than waiting for window-load/document-ready). An example of this would be autofocus, which can irritate if fired too late.
You may be thinking of <style> elements, which aren’t allowed in <body> (although most browsers allow it nonetheless).