Vanilla JavaScript: What You Need to Know

Posted on March 29, 2018 | Updated on March 1, 2021

In its simplest terms, Vanilla JavaScript simply means plain or pure JavaScript. It is a bland type of JavaScript and doesn’t need to pull in coding from libraries or other sources. It’s the simplest form of the language. A library such as jQuery for JavaScript consists of prewritten JavaScript so developers can create various applications and web-centered technology. Vanilla JS is as simple as possible without the need for these prewritten JavaScript libraries.

Perhaps you’ve trained in another form of JS, or you are worried about whether you’ll be able to add the functions you want to a website with such a simple form of JS. It is pretty rare for a designer to use just vanilla or just jQuery, so it is best to look at studying Vanilla JS as just another tool in your design arsenal. If you’re on the fence about using and learning Vanilla JS, here are some things to keep in mind:

1. No Difference Between JavaScript and Vanilla JavaScript

There really is not a difference between regular JavaScript and Vanilla JavaScript. Vanilla is simply a way of referring to using JS in the simplest way possible without the need for pulling in scripts from libraries. If you were going to look at the two as types of cookies, Vanilla JS would be a plain sugar cookie, while regular JS or other types might be a sugar cookie plus icing and maybe even sprinkles and other decorations. The base is the same, but the features and functions change, depending upon what you are trying to accomplish.

2. Vanilla Is Easy to Learn

You can figure out Vanilla JS very quickly. There are numerous YouTube videos that will teach you the basic framework of Vanilla. With just a bit of design knowledge, you’ll be coding in Vanilla within less than an hour, but learning all the eccentricities of JS can take years. Most tutorials start by showing you an accordion script and how you can use that basic framework and personalize your work. You’ll basically start with HTML code.

3. You Should Start With Vanilla

Many experts recommend learning Vanilla JavaScript before moving to fancier JS frameworks. Basically, you are mastering the basics of JS language before trying to become fluent in it. It is similar to the way people learn to speak a foreign language.

Let’s say you’re going on a trip to Spain. When you begin learning Spanish, you are first going to learn how different letters sound in that language. Then, you will begin to learn basic words. Finally, you will learn how to conjugate sentences and hold a conversation in the language. It is the same when you learn a coding language. You must first master the basics and then you can add to your proficiency from there.

4. You Don’t Necessarily Need jQuery

While jQuery provides a library filled with feature-rich options from which you can pull, with today’s more advanced browsers, you can get by without using jQuery and stick with a simpler script. There was a time when you could only choose elements by class, tag and id, but with querySelector, you no longer have to utilize these tags for every action.

5. No Need for the $(document).ready() Function

There was a time when a page couldn’t be manipulated properly unless the document was ready, which meant web developers had to wrap all JS code within the jQuery $(document).ready(). However, you can get the same results by using Vanilla JavaScript and not pulling in the jQuery code. You simply add a document.addEventListener function to your code.

6. Frameworks Differ

As you advance in your use of JS, you’ll probably choose to work with a specific framework. Even though the basic coding language in its simplest terms might be the same, you cannot mix different frameworks. For example, you can’t just plug AngularJS into EmberJS because they are implemented in different ways.

7. Replace jQuery with Pure JavaScript

If you like the sound of Vanilla JS and you’d like to get away from jQuery, you’ll want to use a resource that helps you figure out what the equivalent is to the jQuery you’ve used in the past. You Might Not Need jQuery is a site that allows you to search and see if there is a pure JS that will replace the jQuery. A lot will depend upon the browsers you are writing code for, too.

8. Improve by Reading Frameworks

Think about some of the favorite frameworks you’ve worked with or would like to work with. One way you can enhance your knowledge of pure JavaScript is by reading the source codes on these frameworks. If you’ve spent any time studying Vanilla JS, then you’ll recognize the basic coding structure within this source code. Try to pick out what the underlying code is and what has been changed. Although you’ll need to supplement your studies with courses and reading, this is a great way to learn by studying what other coders do.

9. There Are Some Disadvantages

Even though there are advantages to learning and using Vanilla JS, there are some drawbacks and reasons why you still need to use AngularJS. One advantage of AngularJS is that you have two-way data binding, or the ability for data to be automatically synched between HTML and JS variables. Angular uses HTML as the template language, thus making it extremely easy for those familiar with HTML coding to develop. There are some things you simply can’t accomplish with plain JS.

Vanilla JavaScript Is Worth Learning

There is no denying that you really should learn plain JS language no matter what type of JavaScript you plan to utilize. Understanding the basics allows you to troubleshoot problems later on. It is always smart to start with the simplest form of a language and then build on it from there.

About The Author

Eleanor Hecks is the Editor-in-Chief of Designerly Magazine, an online publication dedicated to providing in-depth content from the design and marketing industries. When she's not designing or writing code, you can find her exploring the outdoors with her husband and dog in their RV, burning calories at a local Zumba class, or curled up with a good book with her cats Gem and Cali.

You can find more of Eleanor's work at www.eleanorhecks.com.

Leave a Comment





Related Posts