I have a Symfony2 project and I have some JavaScript code to be executed.
Where should the .js file be stored in the project and how to call this file (instead of putting the entire script in the .twig)?
Put it in web/js, then access it in your html via:
<script src="{{ asset('js/script.js') }}"></script>
or consider using Assetic.