What is JavaScript?
JavaScript is the programming language used to add behavior, logic, and data processing to web pages.
What you will learn
- What JavaScript is responsible for
- How HTML, CSS, and JavaScript divide responsibilities
- Where JavaScript runs, including browsers and Node.js
- Why events and asynchronous code matter
HTML, CSS, and JavaScript
- HTML
- Defines the structure and meaning of the page.
- CSS
- Controls presentation such as colors, spacing, and layout.
- JavaScript
- Responds to events, processes data, and changes the page.
For example, JavaScript can update a message when a user clicks a button:
<button id="hello" type="button">Say hello</button>
<p id="message"></p>
<script>
document.querySelector('#hello').addEventListener('click', () => {
document.querySelector('#message').textContent = 'Hello, JavaScript!';
});
</script>
Where does it run?
- In a browser, it can respond to input and update the DOM.
- In Node.js, it can run server-side programs and development tools.
- It is also used in desktop, mobile, and game applications.
Key characteristics
- It is dynamically typed: values have types at runtime.
- It is event-driven: user or system events can start a task.
- It uses asynchronous APIs such as Promises to handle work that takes time.