designwithfocus

JavaScript & front end

JavaScript vs React: The Language and the UI Library

By Design With Focus Team 7 min read
A browser script beside a React component function in an editor

Short answer

React is a JavaScript library for UI, and it is not a separate language. MDN describes JavaScript as the scripting language that makes pages update. React's learn page shows components as JavaScript functions that return markup. You write JavaScript either way.

Last verified against the sources listed below.

Key takeaways

  • MDN calls JavaScript a scripting language for dynamic pages, next to HTML and CSS.
  • React's learn page says components are JavaScript functions that return markup.
  • MDN says React is a library for rendering UI components, not a framework by itself.
  • JSX is the markup syntax most React projects use. It is optional, and it is stricter than HTML.
  • React's installation page says Create React App has been deprecated.

A javascript vs react comparison is a language next to a library, not two languages. MDN’s beginner article calls JavaScript a scripting language that lets you build complex features on web pages: timely updates, interactive maps, animated graphics, and video. It is the third layer, after HTML and CSS.

React’s learn page assumes that language. A component is a piece of the user interface with its own logic and appearance. React components are JavaScript functions that return markup. MDN’s frameworks introduction says React itself is not a framework.

It is a library for rendering UI components. React vs javascript is the same pair, read from the library’s side.

You do not choose React instead of JavaScript. You choose whether a UI library should sit on top of the JavaScript you already write. A page of fixed text may not need either a script or a library.

What is JavaScript on the page?

JavaScript is the language that makes the page do something after it loads. MDN’s article lines it up with the other two layers. HTML structures the content. CSS applies style rules such as color, type, and columns.

JavaScript creates updating content, controls multimedia, and animates images. That is the behavior layer beside structure and style.

The article’s button is the small version of that split. HTML creates the button. CSS sets its look. A script waits for a click, asks for a name, and replaces the button’s text.

That script uses the DOM, which MDN describes as the API that creates, removes, and changes HTML. JavaScript is this layer in more detail. It is not a file format you swap for React.

MDN also lists browser APIs that sit beside the language: the DOM, geolocation, canvas and WebGL, and media APIs. Those APIs are how a plain script reaches the browser. React does not replace them. A React app still runs as JavaScript in that environment.

What is React on top of it?

React is a library for describing UI as JavaScript functions. The learn page walks through nesting components, JSX, displaying data inside curly braces, conditions, lists, events, and state. JSX is optional, and most projects use it. It is stricter than HTML.

You close tags, and a component returns one parent, or a fragment. The learn page shows an empty wrapper when you do not want an extra element.

You pass data into a component as props. Event handlers are functions you pass, not functions you call while rendering. State uses useState, which hands back the current value and an updater. Calling the updater re-renders the component.

If two buttons should share a count, you lift that state to the parent and pass it down. HTML is still what the browser shows. JSX looks like HTML and compiles into JavaScript calls.

A SVG to JSX converter turns a graphic into a component function. The output is JavaScript in React’s style, not a new language and not a replacement for the SVG format on disk.

How do the two compare?

The table keeps the language and the library in separate columns. Nothing in it is a download count. Neither MDN’s article nor the React learn page prints one.

JavaScript React
What it is A scripting language for web pages A library for rendering UI components
Who says so MDN’s beginner article MDN’s frameworks introduction, matched to React’s own component model
What you write Scripts that use the language and browser APIs JavaScript functions that return markup
Markup HTML in the document JSX in most projects, which is stricter than HTML
Updates You change the DOM yourself, as in MDN’s button You update state, and React re-renders the component
Required or not The behavior layer when a page must change Optional. The install page says to use as little as you need

React’s installation page says you can add React to an existing HTML page, try it without a local install, or start with a recommended framework. It also says Create React App has been deprecated. A framework is optional packaging around the library. The library is still JavaScript.

When do you stay with JavaScript?

Stay with JavaScript when the behavior is a small script on a document you already understand. MDN’s button does not need components, props, or a build step. You select the button, listen for a click, and set the text. Browser APIs cover a lot of that work: the DOM for structure, Fetch for data, Canvas for drawing.

Stay with JavaScript when you do not want a component model. The frameworks introduction says React is often paired with other libraries to make a full application, and that people sometimes talk about it as a framework because of that pairing. If you only need one interaction, the pairing is extra.

CSS continues to handle presentation in either choice. React’s learn page says you set a CSS class with className, and that React does not prescribe how the stylesheet is added. The simplest case it names is a link element in the HTML. The language and the library both leave that job to CSS.

When do you add React?

Add React when the interface is a tree of pieces that should stay in sync with state. The learn page’s point is that a component function returns the UI for the current data, and a state update runs that function again. Lists use map, and each item needs a key so React can tell the items apart when the list changes. Conditions use ordinary JavaScript, including if.

Add a framework around React when you want that library inside an application shell. Next.js docs call Next.js a React framework for full-stack web applications. You still write React components. Next.js is the framework.

React remains the UI library. The installation page points new apps at a recommended framework and, if that is a poor fit, at building from scratch.

Skip both when the page is static. HTML and CSS already answer that case. React’s own install note about gradual adoption is permission to add a little, not a requirement to add any.

Vue’s introduction calls Vue a JavaScript framework for user interfaces. That framework is still JavaScript, the same language React’s components are written in, not a third language beside the two names in the title.

What do people mix up?

They call React a language. The learn page’s components are JavaScript functions. The file runs because the browser, or a build tool, is running JavaScript. There is no second syntax you can learn instead of functions, objects, and events.

JSX is added syntax for markup, and the learn page says it is optional. Most projects use it, and you can still write React without it.

They quote download totals or a speed winner. The pages opened for this article do not print a download count, and they do not race the language against the library. A library cannot be faster than the language it is written in as a general slogan. It can only change how much DOM work your code does, which these pages describe without a benchmark table.

They treat a deprecated starter as current. The installation page says not to use Create React App. Use the framework path or the from-scratch path that page links, and keep calling React what MDN calls it: a UI library written for JavaScript, not a replacement for it.

Frequently asked questions

Why must a React component name start with a capital letter?

React's learn page says a tag that starts with a capital letter is a component, and HTML tags must be lowercase. That rule is how React tells your function from a built-in element such as a button or a div. The function itself is ordinary JavaScript. If the name is lowercase, React will not treat it as one of your components. The page also says JSX should be wrapped in one parent when you would otherwise return several tags.

Where are you allowed to call a Hook?

The learn page says functions whose names start with use are Hooks, and that useState is a built-in Hook. Hooks are more restrictive than other functions. You may call them only at the top of a component or of another Hook. If you need state inside a condition or a loop, the page says to extract a new component and put the Hook there. That rule is about call order, not about a second language.

What did the installation page say about Create React App?

React's installation page says you should not use Create React App, because it has been deprecated, and it points to a sunsetting note. For a new app, the page points you at a recommended framework. If a framework is a poor fit, it says you can build a React app from scratch or add React to an existing project. Gradual adoption is the opening idea: use as little or as much React as you need, including a little interactivity on an HTML page.

What does a click handler look like on the learn page?

You declare a function inside the component and pass that function to onClick without calling it yourself. React calls it when the user clicks. Calling the handler during render would run it too early. The page then shows useState, which returns the current value and a function that updates it. Calling the updater makes React run the component function again, which the page calls a re-render.

What can a plain script do without React?

MDN's beginner article shows a button, a function that reads a name, and an event listener that replaces the button text. HTML builds the button, CSS styles it, and JavaScript performs the change through the DOM. The same article says the DOM API creates, removes, and changes HTML. You do not need a component function for that snippet. React is for the case where you would rather describe the UI as a function of state.

Sources