Sitemap
Shaibu Barnabas Anibe

Shaibu Barnabas Anibe

Introduction To JavaScript.

7 min readDec 2, 2022

--

Press enter or click to view image in full size
JavaScript.

What Is JavaScript?

JavaScript is a scripting language for creating dynamic web page content. It creates elements for improving site visitors’ interaction with web pages, such as dropdown menus, animated graphics, and dynamic background colors.

JavaScript is a lightweight programming language that web developers commonly use to create more dynamic interactions when developing web pages, applications, servers, and or even games.

What Is JavaScript Used For?

Press enter or click to view image in full size
Photo by Gabriel Heinzer on Unsplash

The initial versions of the scripting language were for internal use only. It was a general-purpose scripting language to ensure web pages’ interoperability across different browsers and devices.

JavaScript has continued to grow alongside new browsers like Mozilla Firefox and Google Chrome since then. The latter even started developing the first modern JavaScript engine, called V8, which compiles bytecode into native machine code.

While it caters to web-based programs the most, JavaScript programming features have other implementations in different areas. The following are several basic uses of JavaScript.

1. Web and Mobile Apps

The development of JavaScript frameworks, consisting of JavaScript code libraries, allows developers to use pre-written JavaScript code in their projects. It saves them time and effort from having to code programming features from scratch.

Each JavaScript framework has features that aim to simplify the development and debugging process.

For example, front-end JavaScript frameworks like jQuery and ReactJS improve design efficiency. They allow developers to reuse and update code components without affecting each other, function or value-wise.

Meanwhile, mobile application development frameworks such as Cordova and Titanium make it possible to create native or hybrid information.

The implementation of JavaScript code in Node.js also plays an important role in web development. Node.js can reduce server response time due to its single-threaded nature and non-blocking architecture and omit delays.

Node.js is also lightweight enough to serve as a scalable tool for microservices, allowing you to develop a single app comprising small services with individual processes.

2. Building Web Servers and Server Applications

Through Node.js, JavaScript lets developers build web servers and back-end infrastructure, saving you time and effort in web server creation.

The built-in HTTP module allows you to develop a basic HTTP server that displays plain text when users access a web page. You can use either the Node.js own web server, Node-OS or third-party ones like Microsoft Internet Information Services (IIS) and Apache to handle the HTTP requests.

Keep in mind that Node-OS works best on the Linux operating systems since it’s built on top of the Linux Kernel.

3. Interactive Behavior on Websites

One of JavaScript’s core functions is adding dynamicity to web pages. This includes displaying animations, modifying text visibility, and creating dropdown menus.

While you can use only HTML and CSS code to build a website, it will only have a static display. With JavaScript, a user can interact with web pages and have a better browsing experience.

Additionally, JavaScript lets you change HTML content and attribute values without reloading the web page first. This is because JavaScript supports the following data types:

  • String ‒ consists of textual data written inside quotes. For example, “Hello world”, ‘Hello world’, and “Display ‘Hello world’ text”.
  • Number ‒ covers integer and floating-point numbers between (2⁵³ — 1) and -(2⁵³ — 1).
  • Boolean ‒ a logical data type with true and false values.
  • BigInt ‒ represents integer data of arbitrary length.
  • Null ‒ contains a null value.
  • Undefined ‒ includes declared but not assigned variables.
  • Symbol ‒ provides unique identifiers for objects.
  • Object ‒ for complex data structures written with curly braces. For example, {item:”Book”, information:”biography”}.

Primitive data types, consisting of all data types except object, can only store a single data. Meanwhile, the object data type can contain a collection of values.

With JavaScript, you can also improve users’ web browsing experience using cookies. Creating, reading, and deleting cookies in JavaScript requires the document.cookie property, which functions as the getter and setter of the cookies’ values.

4. Game Development

JavaScript can help you build a game if used with HTML5 and an Application Programming Interface (API) like WebGL, Plenty of JavaScript-based game engines like Phaser, GDevelop, and Kiwi.JS are available for rendering graphics, code recycling, and cross-platform applications.

Get Shaibu Barnabas Anibe’s stories in your inbox

Join Medium for free to get updates from this writer.

Some of the games made with JavaScript game engines include Angry Birds, The Wizard, and 2048.

What Makes JavaScript Great?

JavaScript has a number of advantages that make it a better choice than its competitors. The following are several benefits of using JavaScript:

  • Simplicity ‒ having a simple structure makes JavaScript easier to learn and implement, and it also runs faster than some other languages. Errors are also easy to spot and correct.
  • Speed ‒ JavaScript executes scripts directly within the web browser without connecting to a server first or needing a compiler. Additionally, most major browsers allow JavaScript to compile code during program execution.
  • Versatility ‒ JavaScript is compatible with other languages like PHP, Perl, and Java. It also makes data science and machine learning accessible to developers.
  • Popularity ‒ plenty of resources and forums are available to help beginners with limited technical skills and knowledge of JavaScript.
  • Server load ‒ another perk of operating on the client-side is that JavaScript reduces the requests sent to the server. Data validation can be done via the web browser, and updates only apply to certain web page sections.
  • Updates ‒ JavaScript development team and ECMA International continuously update and create new frameworks and libraries, ensuring its relevance within the industry.

Features Of JavaScript

JavaScript is divided into two main features, they are as follows –

General JavaScript Features

JavaScript language consists of several different features. Some of the general JavaScript features are as follows –

1. Validating User’s Input

JavaScript is very useful while using forms. It has the capability to validate user input for errors and also saves time. If the user leaves a required field empty or the information is incorrect, JavaScript checks for them before sending the data over to the server.

2. Simple Client-side Calculations

Since JavaScript is a client-side technology, it can perform basic calculations on the browser. The browser does not need to ask server time for every task. This is especially helpful when a user needs to perform these calculations repeatedly. In these cases, connecting to the server would take a lot more time than performing the actual calculations.

3. Greater Control

JavaScript provides greater control to the browser rather than being completely dependent on the web servers. JavaScript provides various browsers with additional functionalities that help reduce server load and network traffic.

4. Platform Independent

Since browsers interpret JavaScript, it solves the problem of compilation and compatibility. Thus it can run on Windows, Macintosh, and other Netscape-supported systems. Also, it is possible to embed them in any other script like HTML that keeps JavaScript into use.

5. Handling Dates and Time

Unlike other programming languages, JavaScript has built-in functions to determine the date and time. Thus it is very easy to code only by using methods like .getDate().

6. Generating HTML Content

JavaScript has very handy features to dynamically generate HTML content for the web. It allows us to add text, links, images, tables, etc after an event occurrence (eg — mouse click).

7. Detecting the User’s Browser and OS

JavaScript is very capable in the detection of the user’s browser and OS information. Though JavaScript runs on every platform, there may occur a situation where we need the user’s browser before processing. This can be helpful for writing code that results in different outputs in different browsers.

Modern JavaScript Features

If we dive into some more recently added features of JavaScript that makes it unique from other programming languages. There are a lot more modern features of JavaScript invented after some general features. Some of them are as follows –

1. Let/Const

JavaScript has introduced the keywords ‘let’ and ‘const’ that are available to replace ‘var’. Unlike ‘var’, they are important due to their blocked scope i.e we can only access them in the block we defined them in. Whereas ‘var’, even if we initialize it inside a function, we can access it outside of the function.

2. Arrow Functions

These functions are very useful in simplifying the syntax and tamp down the lines of codes for the web page or web application. Since these are light-weight in syntax, they can be very easily used in anonymous functions in JavaScript.

3. Template Literal

This is a common feature in other programming languages that allows you to save variables directly into strings. This proves to be an important tool for developers as it permits them to focus more on the development of the application rather than spending the time on syntax.

4. New Array Functions

Though array functions are not necessary for any programming language, they do simplify things for the developer. This also compacts the code and makes it much easier to understand. A regular array and an associative array, JavaScript supports them both. While a regular array contains integer values for its index, indexes can be strings for an associative array.

5. Default Parameters

This JavaScript feature helps to avoid collapsing the whole code for a simple mistake. It is very useful when the developer needs to check the working of a function without any parameters.

6. Property Shorthand

Built-in methods like .get() are available for the developer’s use. These methods help avoid writing the same code every time and cut back on various lines of code. These inborn methods are really supportive of cutting back the developing time and cost.

Conclusion

JavaScript is often used alongside HTML and CSS to add interactivity to websites. In some cases, JavaScript may tap into third-party libraries to provide advanced functionality without the developer having to code it from scratch each time.

Value-wise, JavaScript beginners can expect the following benefits:

  • Easy to learn and implement into certain web page elements or events
  • Backed by a strong community of developers
  • Reduces the requests sent to the server
  • Compatible with many other languages
  • Faster and more lightweight than other programming languages.

--

--