Likewise, you can use altnerative Web Part Layouts to provide your own ASCX markup for that same web part and add your javascript there, but it's very easy to forget that you have a custom layout on that web part, often better to just add Javascript (if that's the type of script you are talking about) through the Page Template or Page tab.
If it's a server script block, then use the Layout on the web part and you can add it there. Without modifying the existing code.