JavaScript is one of the world's most popular programming languages, primarily used to add automation, animations and interactivity to Web pages. Web developers use JavaScript for anything from automating simple tasks to creating complex Web pages that behave like desktop software applications. JavaScript is also used beyond the Web in software, servers and embedded hardware controls.
Run JavaScript in Web Pages
Video of the Day
Used in Web pages, JavaScript is a "client-side" programming language. This means JavaScript scripts are read, interpreted and executed in the client, which is your Web browser. By comparison, "server-side" programming languages run on a remote computer, such as a server hosting a website. The client-side nature of JavaScript allows developers to add interactive features that change and update a Web page without reloading a new copy of the page from the website.
Video of the Day
Implement Basic Automation
In addition to standard programming language features, such as text manipulation and math calculations, JavaScript can access a wealth of information about the browser and the Web page it runs in. JavaScript can use this information to write a custom greeting based on the time of day, add the Web page address in the page footer and optimize the Web page based on the browser you are using.
Update Web Page Content on the Fly
Two important features give JavaScript the power to change a Web page on the fly as you are interacting with it. First, JavaScript is "event-driven," meaning it can respond to events such as mouse clicks, keyboard input, a Web page loading or a timeout being reached. Second, JavaScript has access to the Document Object Model (DOM), an interface to the structure of a Web page. This gives JavaScript access to read and change images, text, form fields, styles, and other elements and attributes of a Web page.
Events and the DOM interface allow JavaScript developers to perform practical tasks, such as validating form input, as well as add interactive features, such as image sliders and games. These are central to the implementation of Dynamic HTML (DHTML).
Communicate with the Cloud
Using Asynchronous JavaScript + XML (Ajax), JavaScript can exchange data with a server. This provides the potential to leverage server-side resources to build powerful Web applications. With Ajax, JavaScript can access computing power, data and specialized server resources that are impractical or impossible to provide in a purely client-side application. For example, Ajax can be used to create form fields that provide suggestions as you type, display search results without reloading the Web page, and provide interactive maps you can explore with a swipe of your mouse cursor.
Know the Benefits and Drawbacks
JavaScript is one of the tools Web developers use to save time with automation, attract website visitors with compelling features and improve the user experience. Developers use JavaScript to add functionality without the need to maintain and support browser-specific add-ons. JavaScript can be used to implement rich Web applications without requiring special software.
However, there is the potential for security issues. JavaScript engine vulnerabilities, Cross-site Scripting (XSS), Cross-site Request Forgery and other exploits can expose website visitors and Web servers to attacks that may compromise sensitive data or damage computing systems.
Potentially, a JavaScript vulnerability could be used to steal your files and private browser data, or install malicious software on your computer. Keep your operating system and browser up-to-date. Protect your computer with antivirus software. Secure your browser by adjusting settings to use high security levels, turn on warnings and prompts, and disable ActiveX and Java. Use care when following links, entering personal information, downloading files and allowing scripts to run.
- IEEE Spectrum: Top 10 Programming Languages
- Mozilla Developer Network: JavaScript
- Microsoft Developer Network: Introduction to Dynamic HTML
- W3C: Document Object Model (DOM)
- Mozilla Developer Network: Ajax
- US-CERT: Securing Your Web Browser
- Codecademy: JavaScript
- W3Schools: JavaScript HTML DOM
- W3Schools: AJAX Tutorial