JavaScript – Basics

Being a developer, if you plan to be a JavaScript Professional, you must know the main Javascript concepts. In this blog, I will start with the basics of Javascript by introducing Javascript and discussing some of its fundamental concepts.

What is JavaScript?

JavaScript is a cross-platform, object-oriented scripting language with can be used within the web browsers to create interactive effects. It is an object-oriented language but not class based as compared to other conventional languages like JAVA. It is a small and lightweight language.

JavaScript can be used on client-side as well as server-side:

  • Client-side JavaScript:  This is the most common form of the language that extends the core language by supplying objects to control a browser and its Document Object Model(DOM). In simple terms, it allows an application to place elements on an HTML form and give a response to various user events such as mouse click, form input, page navigation and so on. It means that a web page need not be a static HTML page, but can also include programs that interact with the user, control the browser, and dynamically create HTML content. In order to achieve this, the script should be included in or referenced by an HTML document for the code to be interpreted by the browser.
  • Server-side JavaScript: This extends the core language by supplying the objects relevant for running JavaScript on the server. For example, it helps an application to communicate with a database, provide a flow of information from one invocation to another in an application and also allow manipulating of files on the server.

JavaScript vs. Java:

The key difference between JavaScript and Java is that: JavaScript is an object-oriented scripting language while JAVA is an object-oriented programming language. JAVA creates applications that run in a virtual machine or browser but JavaScript can run only in the browser. Let’s look at how these languages are presented to the user. Java must be compiled into what is known as a “machine language” before it can be run on the Web i.e. JAVA is a compiled language. On the other hand, JavaScript is text-based. You write it to an HTML document and it is run through a browser i.e. JavaScript is not a compiled language.

JavaScript is much easier and more robust than JAVA. JavaScript is a very free-form language compared to Java. You neither have to declare all variables, classes, and methods nor do you have to be concerned with whether methods are public, private, or protected, and you do not have to implement interfaces. Variables, parameters, and function return types are not explicitly typed.

JavaScript is an object-based language based on prototypes, rather than being class-based like JAVA. Because of this different basis, it can be less apparent how JavaScript allows you to create hierarchies of objects and to have an inheritance of properties and their values. Hence, when we compare JavaScript with JAVA, we are basically comparing prototype-based language vs. class-based language.

Class-based languages like JAVA or C++ are based on the concept of 2 different entities like-  Classes and Instances.

  • Classes: A class defines all of the properties that define a certain set of objects. A class is an abstract thing, rather than any particular member of the set of objects it describes.
  • Instances: An instance, on the other hand, is the instantiation of a class; i.e. it is one of its members.

On the other hand, a prototype-based language, like JavaScript, does not make this distinction: it simply contains objects. It has the notion of a prototypical object, an object used as a template from which to get the initial properties for a new object. Any object can specify its own properties, either when you create it or at run time. In addition, any object can be associated as the prototype for another object, allowing the second object share the first object’s properties.

JavaScript as Functional Programming Language: 

One of the very useful features of JavaScript is that it can be considered as a functional programming language. In JavaScript, a function can be assigned to variables just like any other data types. Not only that, but a function can accept another function as a parameter and can also return a function. You can have functions with no name as well. Clearly, this gives you the ability to code in functional programming style.

So, this is just a short overview of JavaScript. I shall get into details in my following articles. In the next article, we shall dive deep into JavaScript and learn about “values and types, mostly objects” in  JavaScript.

Till then, Keep Reading!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s