The Wayback Machine - https://web.archive.org/web/20240920014713/https://www.geeksforgeeks.org/introduction-to-javascript/
Open In App

Introduction to JavaScript

Last Updated : 27 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

What is JavaScript ?

JavaScript is a lightweight, cross-platform, single-threaded, and interpreted compiled programming language. It is also known as the scripting language for webpages. It is well-known for the development of web pages, and many non-browser environments also use it.

JavaScript is a weakly typed language (dynamically typed). JavaScript can be used for Client-side developments as well as Server-side developments. JavaScript is both an imperative and declarative type of language. JavaScript contains a standard library of objects, like Array, Date, and Math, and a core set of language elements like operators, control structures, and statements. 

  • Client-side: It supplies objects to control a browser and its Document Object Model (DOM). Like if client-side extensions allow an application to place elements on an HTML form and respond to user events such as mouse clicks, form input, and page navigation. Useful libraries for the client side are AngularJS, ReactJS, VueJS, and so many others.
  • Server-side: It supplies objects relevant to running JavaScript on a server. For if the server-side extensions allow an application to communicate with a database, and provide continuity of information from one invocation to another of the application, or perform file manipulations on a server. The useful framework which is the most famous these days is node.js.
  • Imperative language – In this type of language we are mostly concerned about how it is to be done. It simply controls the flow of computation. The procedural programming approach, object, oriented approach comes under this as async await we are thinking about what is to be done further after the async call.
  • Declarative programming – In this type of language we are concerned about how it is to be done, basically here logical computation requires. Her main goal is to describe the desired result without direct dictation on how to get it as the arrow function does.

How to Link JavaScript File in HTML ?

JavaScript can be added to HTML file in two ways:

  • Internal JS: We can add JavaScript directly to our HTML file by writing the code inside the <script> tag. The <script> tag can either be placed inside the <head> or the <body> tag according to the requirement.
  • External JS: We can write JavaScript code in another files having an extension.js and then link this file inside the <head> tag of the HTML file in which we want to add this code.

Syntax:

<script>
    // JavaScript Code
</script>

Example:

HTML
<!DOCTYPE html>
<html lang="en">
 
<head>
    <title>
        Basic Example to Describe JavaScript
    </title>
</head>
 
<body>
 
    <!-- JavaScript code can be embedded inside
        head section or body section -->
    <script>
        console.log("Welcome to GeeksforGeeks");
    </script>
</body>
 
</html>

Output: The output will display on the console.

Welcome to GeeksforGeeks
JavaScript-Introduction

JavaScript Introduction

History of JavaScript

It was created by Brendan Eich in 1995. He was an engineer at Netscape. It was originally going to be named LiveScript but was renamed. Unlike most programming languages, JavaScript language has no concept of input or output. It is designed to run as a scripting language in a host environment, and it is up to the host environment to provide mechanisms for communicating with the outside world. The most common host environment is the browser. 

Features of JavaScript

According to a recent survey conducted by Stack Overflow, JavaScript is the most popular language on earth. With advances in browser technology and JavaScript having moved into the server with Node.js and other frameworks, JavaScript is capable of so much more. Here are a few things that we can do with JavaScript: 

  • JavaScript was created in the first place for DOM manipulation. Earlier websites were mostly static, after JS was created dynamic Web sites were made.
  • Functions in JS are objects. They may have properties and methods just like other objects. They can be passed as arguments in other functions.
  • Can handle date and time.
  • Performs Form Validation although the forms are created using HTML.
  • No compiler is needed.

Applications of JavaScript

  • Web Development: Adding interactivity and behavior to static sites JavaScript was invented to do this in 1995. By using AngularJS that can be achieved so easily.
  • Web Applications: With technology, browsers have improved to the extent that a language was required to create robust web applications. When we explore a map in Google Maps then we only need to click and drag the mouse. All detailed view is just a click away, and this is possible only because of JavaScript. It uses Application Programming Interfaces(APIs) that provide extra power to the code. The Electron and React are helpful in this department.
  • Server Applications: With the help of Node.js, JavaScript made its way from client to server and Node.js is the most powerful on the server side.
  • Games: Not only in websites, but JavaScript also helps in creating games for leisure. The combination of JavaScript and HTML 5 makes JavaScript popular in game development as well. It provides the EaseJS library which provides solutions for working with rich graphics.
  • Smartwatches: JavaScript is being used in all possible devices and applications. It provides a library PebbleJS which is used in smartwatch applications. This framework works for applications that require the Internet for their functioning.
  • Art: Artists and designers can create whatever they want using JavaScript to draw on HTML 5 canvas, and make the sound more effective also can be used p5.js library.
  • Machine Learning: This JavaScript ml5.js library can be used in web development by using machine learning.
  • Mobile Applications: JavaScript can also be used to build an application for non-web contexts. The features and uses of JavaScript make it a powerful tool for creating mobile applications. This is a Framework for building web and mobile apps using JavaScript. Using React Native, we can build mobile applications for different operating systems. We do not require to write code for different systems. Write once use it anywhere!

Limitations of JavaScript

  •  Security risks: JavaScript can be used to fetch data using AJAX or by manipulating tags that load data such as <img>, <object>, <script>. These attacks are called cross-site script attacks. They inject JS that is not part of the site into the visitor’s browser thus fetching the details. 
  • Performance: JavaScript does not provide the same level of performance as offered by many traditional languages as a complex program written in JavaScript would be comparatively slow. But as JavaScript is used to perform simple tasks in a browser, so performance is not considered a big restriction in its use.
  • Complexity: To master a scripting language, programmers must have a thorough knowledge of all the programming concepts, core language objects, and client and server-side objects otherwise it would be difficult for them to write advanced scripts using JavaScript.
  • Weak error handling and type checking facilities: It is a weakly typed language as there is no need to specify the data type of the variable. So wrong type checking is not performed by compile.

Why JavaScript is known as a lightweight programming language ?

JavaScript is considered lightweight due to the fact that it has low CPU usage, is easy to implement, and has a minimalist syntax. Minimalist syntax as in, has no data types. Everything is treated here as an object. It is very easy to learn because of its syntax similar to C++ and Java.

A lightweight language does not consume much of your CPU’s resources. It doesn’t put excess strain on your CPU or RAM. JavaScript runs in the browser even though it has complex paradigms and logic which means it uses fewer resources than other languages. For example, NodeJs, a variation of JavaScript not only performs faster computations but also uses fewer resources than its counterparts such as Dart or Java.

Additionally, when compared with other programming languages, it has fewer in-built libraries or frameworks, contributing as another reason for it being lightweight. However, this brings a drawback in that we need to incorporate external libraries and frameworks. 

Is JavaScript Compiled or Interpreted or both ?

JavaScript is both compiled and interpreted. In the earlier versions of JavaScript, it used only the interpreter that executed code line by line and shows the result immediately. But with time the performance became an issue as interpretation is quite slow. Therefore, in the newer versions of JS, probably after the V8, the JIT compiler was also incorporated to optimize the execution and display the result more quickly. This JIT compiler generates a bytecode that is relatively easier to code. This bytecode is a set of highly optimized instructions. 
The V8 engine initially uses an interpreter, to interpret the code. On further executions, the V8 engine finds patterns such as frequently executed functions, and frequently used variables, and compiles them to improve performance.

JavaScript is best known for web page development but it is also used in a variety of non-browser environments. You can learn JavaScript from the ground up by following this JavaScript Tutorial and JavaScript Examples.

Introduction to JavaScript – FAQs

What is JavaScript?

JavaScript is a high-level, dynamic programming language used to make web pages interactive. It is a core technology of the World Wide Web, alongside HTML and CSS.

What is JavaScript used for ?

JavaScript is a versatile programming language primarily used for web development. It adds interactivity, dynamic content, and enhanced user experiences to websites. With JavaScript, you can create features like sliders, interactive forms, animations, and more. It’s also widely used in building web applications, backend services (using Node.js), game development, and even mobile apps.

What is the difference between JavaScript and Java?

JavaScript and Java are distinct languages with different purposes. Java is an object-oriented programming language for building standalone applications, while JavaScript is primarily used to enhance web pages with interactivity and dynamic content.

What is JavaScript DOM ?

The JavaScript DOM (Document Object Model) is a programming interface that allows you to interact with and manipulate HTML and CSS. The DOM represents the structure of a web page as a tree of objects that JavaScript can modify. You can use the DOM to update content, change styles, handle events, and interact with elements in real-time, making your web pages dynamic and responsive.

How do you include JavaScript in an HTML document?

JavaScript can be included in an HTML document in three ways:

  • Inline, by placing it directly within HTML elements.
  • Internal, by placing it within a <script> tag in the HTML document.
  • External, by linking to a separate .js file using the <script src=”filename.js”></script> tag.

What are variables in JavaScript?

Variables in JavaScript store data values. They can be declared using var, let, or const.



Previous Article
Next Article

Similar Reads

Introduction to JavaScript Course - Learn how to build a task tracker using JavaScript
This is an introductory course about JavaScript that will help you learn about the basics of javascript, to begin with, the dynamic part of web development. You will learn the basics like understanding code structures, loops, objects, etc. What this course is about? In this course we will teach you about the basics of the scripting language i.e) Ja
4 min read
Introduction to Object Oriented Programming in JavaScript
As JavaScript is widely used in Web Development, in this article we will explore some of the Object Oriented mechanisms supported by JavaScript to get the most out of it. Some of the common interview questions in JavaScript on OOPS include: How is Object-Oriented Programming implemented in JavaScript? How does it differ from other languages? Can yo
7 min read
Introduction to Built-in Data Structures in JavaScript
JavaScript (JS) is the most popular lightweight, interpreted compiled programming language, and might be your first preference for Client-side as well as Server-side developments. Let's see what inbuilt data structures JavaScript offers us: Data Structure Internal Implementation Static or Dynamic JavaScript Arrays Contiguous Memory Allocation Dynam
2 min read
A Quick Introduction to pipe() and compose() in JavaScript
Functional programming is gaining popularity in JavaScript development. Two fundamental concepts in functional programming are function composition and piping, which are implemented using compose() and pipe() respectively. These concepts allow for the creation of complex operations by combining simple functions in a clear and readable manner. In th
3 min read
Introduction to Javascript Engines
JavaScript is a scripting language and is not directly understood by computer but the browsers have inbuilt JavaScript engine which help them to understand and interpret JavaScript codes. These engines help to convert our JavaScript program into computer-understandable language.  A JavaScript engine is a computer program that executes JavaScript co
4 min read
Introduction to React Native
If you want to build mobile apps for both Android and iOS. What should you learn? The individual native languages for each app i.e, Java for Android and Swift/Objective-C for iOS?, Actually NO. Native Android and iOS development are quite different and can be expensive – first, the language itself is quite different, and second, all the underlying
3 min read
PHP | MySQL Database Introduction
What is MySQL? MySQL is an open-source relational database management system (RDBMS). It is the most popular database system used with PHP. MySQL is developed, distributed, and supported by Oracle Corporation. The data in a MySQL database are stored in tables which consists of columns and rows.MySQL is a database system that runs on a server.MySQL
4 min read
Django Introduction | Set 2 (Creating a Project)
Note- This article is in continuation of Django introduction. Popularity of Django Django is used in many popular sites like as: Disqus, Instagram, Knight Foundation, MacArthur Foundation, Mozilla, National Geographic etc. There are more than 5k online sites based on Django framework. ( Source ) Sites like Hot Frameworks assess the popularity of a
3 min read
Introduction to Xamarin | A Software for Mobile App Development and App Creation
The entire world is now surrounded by billions and trillions of mobile Tech which is inevitable. The major share of the development of mobile apps is taken by the Google's Android, Apple's iOS, and Microsoft's Windows. Every new learner or newbie in Mobile Development Domain finds himself in the dilemma of choosing the platform to start with. They
9 min read
WebGL Introduction
Creating interactive media content for the web traditionally required third-party apps or plug-ins installed in browsers. With the rise of open web standards and the need to support native graphics capabilities in the web browsers, WebGL was born to bring cross-browser compatibility and to be fully integrated with web standards. What is WebGL? WebG
4 min read
Introduction to Web Development and the Holy Trinity of it
Introduction and Holy Trinity of Web Development This article will give you an overview of the Front End Development, Back-End Development, and the Full Stack Development and will give you an idea about each of them in detail so that you can decide your field of interest for yourself. Starting from the basic book definition, ‘Web development refers
12 min read
Ajax Introduction
Introduction: The following tutorial will provide a short introduction to Ajax and its uses. Before understanding these terms see few practical examples to demonstrate the power of Ajax. Facebook, Instagram, Twitter etc are considered the situation when check news feed and if like someone post simply click the like button and the like count is adde
7 min read
Introduction to Scripting Languages
All scripting languages are programming languages. The scripting language is basically a language where instructions are written for a run time environment. They do not require the compilation step and are rather interpreted. It brings new functions to applications and glue complex system together. A scripting language is a programming language des
3 min read
Introduction to React-Redux
The ones familiar with react will know that react is a component-based front end library tool that connects the various segments of the web page. In react, we use props (short for properties) in a component which allows the usage of non-static variables. With the help of props, we can pass these variables into various other components (child compon
5 min read
p5.js Introduction
p5.js is a JavaScript library used for creative coding. It is based on Processing which is a creative coding environment. The main focus of processing is to make it easy as possible for beginners to learn how to program interactive, graphical applications, to make a programming language more user-friendly by visualizing it. The advantage of using t
2 min read
PHP | Spreadsheet_Excel_Writer | Introduction
Introduction: Spreadsheet_Excel_Writer is a library written in PHP which helps to read from and write to different types of spreadsheet file formats with the help of given set of classes. Advantages: Easy and effective comparisons. Powerful analysis of large amounts of data. Splitting out large (or not so large) amounts of information in the form o
1 min read
Introduction to HTML CSS | Learn to Design your First Website in Just 1 Week
This is an introduction course to HTML and CSS which will help you learn all about the basics of HTML and CSS needed to begin with Web Development. Course Overview In this course we will teach you the basics of HTML and CSS along with building a project which will be a single page website. That is by following this course you will also get the chan
4 min read
Introduction to WebRTC
WebRTC stands for Web Real-Time Communication. It is an open source and free project that used to provide real-time communication to mobile applications and web browsers with the help of API's(Application Programming Interface). This project emerged as a new standard which extends the web-browsing model by enabling the browser in a peer-to-peer man
5 min read
Meteor Introduction and Environment Setup
Meteor is an open-source full-stack JavaScript platform that is useful for developing modern web and mobile applications. Meteor helps the developer to develop in one language. Meteor has several features that help for creating a responsive and reactive web or mobile application using JavaScript or different packages available in the framework. For
2 min read
HTML5 | Introduction
Introduction: HTML stands for Hyper Text Markup Language. It is used to design web pages using a markup language. HTML is an abbreviation of Hypertext and Markup language. Hypertext defines the link between the web pages. The markup language is used to define the text document within the tag which defines the structure of web pages. HTML 5 is the f
6 min read
Introduction about Node.js and MongoDB
NoSQL databases are databases that store and retrieve the data that is present in a non-tabular format. Depending on the format of the data stored, NoSQL databases are split into 4 major types: Key-Value Graph database Document-oriented Column family These databases are built to address the shortcomings of traditional RDBMS and provide high perform
4 min read
Introduction to Express
Prerequisite - Node.js What is Express? Express is a small framework that sits on top of Node.js's web server functionality to simplify its APIs and add helpful new features.It makes it easier to organize your application's functionality with middle ware and routing; it adds helpful utilities to Node.js's HTTP objects;it facilitates the rendering o
2 min read
Introduction to KnockoutJS
BASIC INTRODUCTION: Knockout is a library written in JavaScript and based on MVVM (MODEL VIEW VIEWMODEL) pattern. It helps in building rich and responsive websites. It works with any framework and handles data driven interfaces. KO is the abbreviated name of Knockout. The KO library file is small and light-weight. PREREQUISITES: HTML, CSS, JAVA SCR
3 min read
General Introduction to Progressive Web Apps(PWA)
What is an App? Must be findable in App Store Icons must be present on Home Screen Touch and Gesture Controls Works Offline Receives push notifications Background processing Access to hardware features and sensors What is the Web ? Contains URLs and Links Markup and styling that must be readable by both humans and machines Progressively enhanced Fr
2 min read
Introduction to Codeignitor (PHP)
Codeignitor is one of the popular MVC framework of PHP. Most of the developers prefer to make their projects on Codeignitor because of it's lightweight and easy to understand documentation. Some of the features, advantages or why use Codeignitor is given below. Why use Codeignitor? Fast and lightweight because it's library consume less memory. Easy
4 min read
script.aculo.us Introduction
script.aculo.us can be used for enhancing the GUI and giving Web 2.0 experience to the users. script.aculo.us allows us to add dynamic visual effects and user interface in our web via the Document Object Model. It is a JavaScript library built on top of the Prototype JavaScript Framework. Downloading script.aculo.us Download scriptaculous.zip packa
1 min read
Introduction to Sockets.IO in Node.js
Sockets.IO : Earlier, websites used to reload every-time a resource was requested. This introduced unnecessary delays which increased average wait time. Often users had to wait for minutes to fetch a particular page or file. Real-time applications(Instant messenger, Online gaming, push notification etc), on the other hand, are those applications wh
8 min read
Laravel | Artisan Console Introduction
Laravel has its own Command Line interface called Artisan. Its like a Linux command line but the commands are helpful for building a Laravel application. With this command-line tool, we can make models, controllers, and can do data migrations and many more. First, we will have to change the directory in your command line console (i.e. cmd on window
2 min read
Introduction to Git Branch
Branching means diverging from the mainline and continue to work separately without messing with the mainline. Nearly every VCS has some form of branch support. In Git, a branch is simply a reference to the commit, where the following commits will be attached. Git vs SVN: In recent years, the use of git has risen tremendously. Unlike SVN, git allow
3 min read
Angular 7 | Introduction
Angular 7 is a TypeScript based front-end web framework by Google. It enables you to create Single Page Applications(SPA) with the help of the concept of components. The components in Angular 7 are structured like a tree i.e. there are parent and child components in which each child component is connected to its respective parent component. Single
2 min read