Storing and Using Scripts

JavaScript can be embedded directly inside a web page or stored as a separate script file. Before getting started with the language, let’s look at where you can write JavaScript, how you store it, and how you can include it in your pages.

Embed Script on a Page

You can embed JavaScript code directly inside a page. This is true of .html pages and .cshtml views (and other .NET pages). The JavaScript will execute where it is found within the page. Later in this chapter, you will see how you can use events to determine when your JavaScript code should execute.

The JavaScript code placed inside a page should be contained within a <script> tag. The <script> tag looks like this.

<script type="text/javascript"> ...

Get Microsoft Visual Studio 2015 Unleashed, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.