Exploring JavaScript
2015-06-03 19:56
543 查看
When learning a new programming language, it's important to try the examples in the book, and then modify them and try them again to test your understanding of the language. To do that, you need a JavaScript interpreter. Fortunately, every web browser includes a JavaScript interpreter, and if you're reading this book, you probably already have more than one web browser installed on your computer.
We'll see later on in this chapter that you can embed JavaScript code within <script> tags in HTML files. and when the browser loads the file, it will execute the code. Fortunately, however, you don't have to do that every time you want to try out simple snippets of JavaScript code. Spurred on by the powerful and innovative Firebug extension for Firefox(pictured in Figure 1-1 and available for download from http://getfirebug.com/), today's web browsers all include web developer tools that are indispensable for debugging, experimenting, and learning. You can usually find these tools in the Tools menu of the browser under names like "Developer Tools" or "Web Console."(Firefox 4 includes a built-in "Web Console", but at the time of this writing, the Firebug extension is better.) Often, you can call up a console with a keystroke like F12 or Ctrl-Shift-J. These console tools often appear as panes at the top or bottom of the browser window, but some allow you to open them as separate windows(as pictured in Figure 1-1), which is often quite convenient.
A typical "developer tools" pane or window includes multiple tabs that allow you to inspect things like HTML document structure, CSS styles, network requests, and so on. One of the tabs is a "JavaScript console" that allows you to type in lines of JavaScript code and try them out. This is a particularly easy way to play around with JavaScript, and I recommend that you use it as you read this book.
There is a simple console API that is portably implemented by modern browsers. You can use the function console.log() to display text on the console. This is often surprisingly helpful while debugging, and some of the examples in this book(even in the core language section) use console.log() to perform simple output. A similiar but more intrusive way to display output or debugging messages is by passing a string of text to the alert() function, which displays it in a modal dialog box.
We'll see later on in this chapter that you can embed JavaScript code within <script> tags in HTML files. and when the browser loads the file, it will execute the code. Fortunately, however, you don't have to do that every time you want to try out simple snippets of JavaScript code. Spurred on by the powerful and innovative Firebug extension for Firefox(pictured in Figure 1-1 and available for download from http://getfirebug.com/), today's web browsers all include web developer tools that are indispensable for debugging, experimenting, and learning. You can usually find these tools in the Tools menu of the browser under names like "Developer Tools" or "Web Console."(Firefox 4 includes a built-in "Web Console", but at the time of this writing, the Firebug extension is better.) Often, you can call up a console with a keystroke like F12 or Ctrl-Shift-J. These console tools often appear as panes at the top or bottom of the browser window, but some allow you to open them as separate windows(as pictured in Figure 1-1), which is often quite convenient.
A typical "developer tools" pane or window includes multiple tabs that allow you to inspect things like HTML document structure, CSS styles, network requests, and so on. One of the tabs is a "JavaScript console" that allows you to type in lines of JavaScript code and try them out. This is a particularly easy way to play around with JavaScript, and I recommend that you use it as you read this book.
There is a simple console API that is portably implemented by modern browsers. You can use the function console.log() to display text on the console. This is often surprisingly helpful while debugging, and some of the examples in this book(even in the core language section) use console.log() to perform simple output. A similiar but more intrusive way to display output or debugging messages is by passing a string of text to the alert() function, which displays it in a modal dialog box.
相关文章推荐
- Json转换利器Gson之实例一-简单对象转化和带泛型的List转化
- 用js实现类数组转换为数组
- Javascript中的原型继承详解
- 解析json字符串三种方法
- ExtJS4图片验证码的实现
- Extjs中引入JSP页面
- JS-Geolocation API
- JS-资料收录
- JS-通信API
- JS-Web Workers处理线程
- Gson 字符串和json对象的转换
- JS-Web Storage
- 用过滤器来解决JSP中文乱码问题
- JS-JSON数组
- JS-获取navigator信息
- JS-获取url信息
- JS-获取对象位置信息
- JS-精确四则运算
- jsp下显示硬盘下绝对路径下的中文文件名的图片
- jsp借助了ajaxfileupload实现上传文件