What is JavaScript?
Introduction
JavaScript is a programming language that adds dynamic functionality and complex features like interactivity and animation to web pages. Together with HTML and CSS, JavaScript forms the foundation of web development.
The language is used heavily in web pages, but now various JavaScript platforms allow you to execute JavaScript on a server without a browser. It is also used to create mobile apps for Android and iOS platforms.
Read on for more information about how it works and the different careers that use it!
How JavaScript works
JavaScript is a client-side scripting language, which means that it’s a programming language that can run inside a web browser. There are other languages (like Flash) that run in browsers, but JavaScript is currently the only one that you can use in all the popular browsers.
JavaScript’s popularity comes (in part) from its custom features that deal with the web browser environment. Let’s look at some of these features, such as variables, operations, and integration with APIs.
JavaScript variables
JavaScript’s variables allow developers to capture a value in one place and use it in another. For example, say your website includes a field for visitors to enter their first name in a web form. With JavaScript, you could set a variable named firstName
to hold their name and greet them with it by printing it on a different part of the page.
Text and mathematical operations
Sometimes developers need to do more than print a variable. They may also need to modify or transform it.
Say you wanted to greet visitors with their full names instead. With JavaScript, you could join a firstName
variable with a lastName
variable to create a fullName
variable.
JavaScript can also perform mathematical operations, like adding all the products in an order form to calculate a total.
Listening for and responding to events
Specifically, events that happen in a web browser. For example, it can respond to the click of a button by executing code that prepares the data in web form and submits it.
Interacting with web APIs
JavaScript’s versatility allows it to interact with APIs (Application Programming Interfaces), including REST APIs, which are remotely accessible through the internet. APIs are functions in software that developers leave open so that other developers can access them with their own software.
Many applications and websites provide APIs, like Twitter and Facebook. With Twitter’s API, you can use JavaScript to connect to it and print Tweets on your web page.
How JavaScript is used
You can use JavaScript in quite a few ways. Below, we explore some of its most popular applications: web development, mobile development, and game development.
Web development
Front-end web developers use JavaScript to add interactive behavior to web pages. These behaviors include:
- Showing or hiding information with the click of a button
- Changing the color of a button when a mouse pointer hovers over it
- Playing audio or video embedded in a web page
- Rotating through images in a slide show
- Animating elements on a page when they are shown or hidden
- Showing a drop-down menu when an element is clicked
- Displaying a count-down timer on a web page
Back-end web developers also use JavaScript on web servers, where it connects to databases and APIs to retrieve and transform data before sending it to another application. (Check out our courses on web development to learn more.)
Mobile development
Several frameworks extend JavaScript’s use into mobile development. With these frameworks, JavaScript can interact with both Android and iOS phones — allowing developers to build apps for both platforms with a single language.
Game development
Web-based games are very popular, and after browsers stopped supporting Flash, JavaScript became the only way to create dynamic 2D or 3D in-browser games. Frameworks like Phaser.js extend JavaScript’s utility in game development even further.
JavaScript libraries and frameworks
You can build an entire application from scratch with just JavaScript, but most modern development also includes libraries and frameworks. Libraries and frameworks are sets of pre-written code with pre-built components you can use to develop your projects more quickly and easily. Some of JavaScript’s most popular libraries and frameworks include React, Angular, and Vue.
React
React is a popular JavaScript front-end library developed by Facebook. Front-end developers use React to build interactive user interfaces and reusable web components that together create complete web applications.
React is consistently ranked as one of the most popular frameworks for web development. Last year, over 68% of developers surveyed by Stack Overflow chose React as their “Most Loved’ web framework.
Angular
Angular is another popular JavaScript framework developed by Google. It’s a much larger framework with an arguably steeper learning curve as it comes with built-in tools that perform form management, client-server communication, and other functionalities.
Vue.js
Vue.js is a lightweight JavaScript framework that many developers find to be the easiest to learn. It has an HTML-based syntax and gives you the option to pick what you want to use from the framework. The core of Vue.js handles the user interface, like React, but you can also choose to use more features of the framework to add data models, view controllers, and more.
Learn more about JavaScript
As you can see, JavaScript holds a wide range of applications. Now that you understand how it’s used, the next step is to start using it yourself. If you’re new to programming, check out our Learn JavaScript course. We’ll teach you the fundamentals of JavaScript and object-oriented programming.
If you’re already familiar with the language and want to explore its uses in front-end development, now’s the time to Learn React or Vue.js.
More interested in back-end development? Learn how to use Node.js, Express.js, SQL, and more to create a back-end app with JavaScript. Or, delve into our Front-End and Back-End Engineer Career Paths to build all the skills you’ll need to pursue a career in web development.
Author
'The Codecademy Team, composed of experienced educators and tech experts, is dedicated to making tech skills accessible to all. We empower learners worldwide with expert-reviewed content that develops and enhances the technical skills needed to advance and succeed in their careers.'
Meet the full teamRelated articles
Learn more on Codecademy
- Skill path
Code Foundations
Start your programming journey with an introduction to the world of code and basic concepts.Includes 5 CoursesWith CertificateBeginner Friendly4 hours - Career path
Full-Stack Engineer
A full-stack engineer can get a project done from start to finish, back-end to front-end.Includes 51 CoursesWith Professional CertificationBeginner Friendly150 hours