3 ways of including JavaScript in HTML

Code written in JavaScript must be executed from a document written in HTML.

There are three ways of doing this :

1. you can place the JavaScript between <script> tags within the <head> of the document :

2. a much better technique is to place your JavaScript code into a separate file.

3. the best way is to place the <script> tag at the end of the document right before the closing

</body> tag :

Placing the <script> tag at the end of the document lets the browser load the page faster.



Programming languages are either interpreted or compiled. Languages like Java or C++ require a

compiler. A compiler is a program that translates the source code written in a high-level language like Java into a file that can be executed directly by a computer.

Interpreted languages dont require a complier -- they just need an interpreter instead.

With JavaScript, in the context of the World Wide Web, the web browser does the interpreting.

Without the interpreter, the JavaScript code would never be executed.

If there are any errors in the code written in a compiled language, those errors will pop up when the code is compiled. In the case of an interpreted language, errors won’t become apparent until the interpreter executes the code

时间: 2024-08-03 08:53:43

3 ways of including JavaScript in HTML的相关文章

JavaScript Libraries In A TypeScript Application, Revisited

If you haven't already gotten involved with it, you'll probably know that TypeScript is becoming increasingly popular. Being able to use a superset of javascript in a typed language that compiles down to JavaScript is a great thing. However,if you've

Function Smackdown: Function Statement vs. Function Expression

I’ve recently been reading ‘JavaScript: The Good Parts,’ by Douglas Crockford. This concise book defines a subset of core JavaScript that’s robust and powerful: The Good Parts. Appendix B identifies The Bad Parts, and sets our competitors - the funct

轻松解决Linux安装Eclipse方法

随着Linux的发展,很多人开始学习Linux系统,你了解Linux系统么?你是Linux系统的应用者么?本文为你详细介绍Linux安装Eclipse,为你在学习Linux安装Eclipse时起一定的作用.以下是Linux安装Eclipse完全攻略. 1. ubuntu 下安装Eclipse 1.1 在Ubuntu搭建java开发环境 (1)安装好Ubuntu系统:安装的时候强烈建议连接上网,它会自动下载语言包,自动装上五笔,拼 音,还有会默认把firefox浏览器设置为中文. (2)配置Ubu

翻译:打造Edge渲染内核的浏览器

最近开始了解UWP和Edge内核,在微软技术博客中找到一篇文章,主要是介绍Edge渲染内核使用技术.顺手翻译了一下.不对之处请斧正! Over the past several months, we have made numerous improvements to theMicrosoft Edge rendering engine (Microsoft EdgeHTML), focusing oninteroperability with modern browsers and compl

20+ Docs and Guides for Front-end Developers (No. 5)

It’s that time again to choose the tool or technology that we want to brush up on. If you feel like you’ve been working hard at building but maybe not learning as much as you’d like, I’ve got your back covered. Please enjoy the fifth installment of o

转义HTML字符

package util; public final class HTMLFilter { /** * Filter the specified message string for characters that are sensitive * in HTML. This avoids potential attacks caused by including JavaScript * codes in the request URL that is often reported in err

3 Ways to Preload Images with CSS, JavaScript, or Ajax---reference

Preloading images is a great way to improve the user experience. When images are preloaded in the browser, the visitor can surf around your site and enjoy extremely faster loading times. This is especially beneficial for photo galleries and other ima

3 ways to define a JavaScript class

3 ways to define a JavaScript class September 29th, 2006. Tagged: JavaScript Introduction JavaScript is a very flexible object-oriented language when it comes to syntax. In this article you can find three ways of defining and instantiating an object.

What is the difference between the ways to implement inheritance in javascript.

see also : http://www.w3school.com.cn/js/pro_js_inheritance_implementing.asp http://davidshariff.com/blog/javascript-inheritance-patterns/ Object masquerading with Javascript Posted on October 7, 2010 by Amit Agarwal Often people follow this common a