Glossary

What is JavaScript? A Basic Introduction to JS for Beginners

What is JavaScript?

JavaScript is one of the world’s most popular programming languages with over twenty years of history. It’s also one of the three main languages for web developers:

  1. HTML: Lets you add content to a web page.
  2. CSS: Specifies the layout, style, alignment of web pages.
  3. JavaScript: Improves the way web pages behave.

JavaScript can be learned quickly and easily and used for a wide variety of purposes, from simply enhancing the functionality of a website to running games and web-based software. Better still, there are thousands of JavaScript templates and applications available for free thanks to sites like Github.

Looking for a place to hone your JS skills? Grab a web hosting plan and get all the essential web master tools to turn your code into responsive websites!

JavaScript from then until now

JavaScript was created over a period of ten days by Brandan Eich, a Netscape employee, back in September 1995. Initially called Mocha, the language’s name was changed to Mona and then LiveScript before eventually becoming known as JavaScript. Initial versions of the language were limited exclusively to Netscape and only offered limited functionality, but it’s continued to grow over time thanks in part to the community of developers who continue to work with it.

In 1996, JavaScript was officially given the name of ECMAScript, with ECMAScript 2 coming out in 1998 and ECMAScript 3 following up in 1999. This evolved into today’s JavaScript, which now works not only across different browsers but also on different devices including mobiles and desktop computers.

JavaScript has continued to grow ever since, to the point at which 92% of websites were using JavaScript by 2016. In just twenty years it’s gone from a primitive programming language to one of the most important tools in a web developer’s toolbox. If you’ve used the internet, then you’ve probably encountered JavaScript too.

What makes JavaScript great?

JavaScript has a number of advantages that make it a better choice than its competitors, especially in certain use cases. Just a few of the benefits to using JavaScript include:

  1. You do not need a compiler because web browsers interpret it with HTML;
  2. It’s easier to learn than other programming languages;
  3. Errors are easier to spot and therefore to correct;
  4. It can be assigned to certain web page elements or specific events such as clicks or mouseovers;
  5. JS works across multiple browsers, platforms, etc;
  6. You can use JavaScript to validate inputs and reduce the need for manual data checks;
  7. It makes websites more interactive and holds visitors’ attentions;
  8. It’s faster and more lightweight than other programming languages.

What are JavaScript’s weaknesses?

There are weaknesses to every programming language you can think of. Part of the problem is that when a programming language becomes as popular as JavaScript is, there’s an added incentive for hackers, scammers and other malicious third parties to try to find loopholes and security flaws. Some weaknesses include:

  1. Vulnerable to exploits;
  2. Can be used to execute malicious code on a user’s computer;
  3. Not always supported by different browsers and devices;
  4. JS code snippets are quite large;
  5. Can be rendered differently on different devices leading to inconsistency.

How does JavaScript work on your website?

JavaScript is usually either embedded directly into a web page or referenced via a separate .js file. It’s a client-side language which means that the script is downloaded to visitors’ machines and processed there as opposed to a server-side language which is executed on your server before it sends the files to visitors.

Bear in mind that most web browsers also offer the ability for users to disable JavaScript. That’s why it’s a good idea to specify what happens in the event that it’s downloaded to a machine that doesn’t support it.

How JavaScript differs from other programming languages?

The reason why JavaScript is one of the most popular programming languages of all is the fact that it’s so versatile. In fact, many developers turn to it as their programming language of choice and only turn to the others on this list when they need something a little more specific.

Let’s take a look at a few of the most popular programming languages:

JavaScriptJavaScript or JS for short is all about adding interactivity to websites. The scripts run in the user’s browser as opposed to the server and typically tap into third-party libraries to provide advanced functionality without the developer having to code it from scratch each time.
HTMLShort for “Hypertext Markup Language”, HTML is one of the most common programming languages on the web and forms the building blocks of a web page. Examples of HTML tags include <p> for paragraphs and <img> for images.
PHPPHP is a server-side language as opposed to JavaScript which runs on the client’s machine. It’s most commonly seen in PHP-based content management systems like WordPress, but it’s also commonly used for back-end development as it provides the perfect way to facilitate the transfer of information to and from a database.
CSSCSS stands for “Cascading Style Sheets” and allows webmasters to specify styles and to define the way that different types of content are displayed. You could do this manually for every element in the HTML, but by doing it in the CSS you save yourself from repeatedly having to specify how elements are displayed every time you use them.

If we compare programming to building a house, the HTML would specify the structure of the house and where the walls and doorways are while the CSS would cover the carpets and the wallpapers that decorate the house and make it look beautiful. The JavaScript adds the responsiveness and means that you can open doors and turn on light switches. You can manage without it but you risk your website looking and acting like a flashback from 1995.

How do you add JavaScript on a website?

To insert a string of JavaScript code into a webpage, you’ll need to use the <script> tag. You can use the following example to see what that looks like in practice:

<script type="text/javascript">
Your JavaScript code
</script>

As a general rule, it’s a good idea to include your JavaScript inside the <header> tags for your website unless it needs to be executed at a specific time or with a specific web page element. You can also save your JavaScript code as separate files and call them up as needed throughout the website.

To learn more, you can check out our other guide that’s all about adding JavaScript to your website.

So, what is JavaScript?

JavaScript is a programming language which brings websites to life. This is in contrast to HTML (which specifies content) and CSS (which specifies layout) and unlike PHP, it runs on visitors’ devices instead of the server.

What you need to know:

  1. JavaScript is relatively easy to learn;
  2. It is developed by Netscape, it’s now used on 92% of websites;
  3. JS can be assigned to certain web page elements or events like clicks;
  4. It works across different browsers and devices;
  5. It’s faster and more lightweight than other programming languages;
  6. Can be less secure than other options due to its popularity;
  7. You can either add JavaScript directly to HTML or you can store it in separate files and call the functionality as needed.

Ultimately, there’s a reason why JavaScript is as popular as it is: it’s very good at what it does. So if you’ve been wondering about it, we hope this resource has helped and that you now have a good idea of what JavaScript is and how it works.

And of course, if you have any further questions, then you should let us know in the comments!

About the author

Gediminas B.

Gediminas is a passionate content writer and SEO geek at Hostinger. He started his journey at customer support and aims to use his gathered knowledge to create the most epic content the world has ever seen. From WordPress to server management, there's no topic he can't cover! He also likes cats.

Add Comment

Click here to post a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

[href]
[href]
More in Glossary
What is Apache HTTP Server
What is Apache? An In-Depth Overview of Apache Web Server

Close