JavaScript : Advantages and disadvantages of External JavaScript ?

Advantages :

Following are the Advantages of javaScript over external :-

  • Reusability of code.
  • Easy code readability.
  • It Enables both web designers and coders to work with html and js files.
  • With these small js files, you can use Google closure or YUI Compressor or other minifying tools to reduce the size and make it not readable by humans .

Disadvantages :

Following are the disadvantages of javaScript over external :-

  • Code can be downloaded using the url of the js file. This can help coders to steal your code easily.
  • If two js files are dependent on one another, then a failure in one file may affect the execution of the other dependent file.
  • A small change to a common js file may cause unexpected results in some of the HTML files .
  • The browser has to make an extra http request to get the js code.
Tagged : / / / / / /

JavaScript : Where to use javaScript code

JavaScript code use in following :

  1. Between the body tag of html
  2. Between the head tag of html
  3. In .js file (external javaScript)

1. JavaScript use between html body tag :

Example of javaScript using inside html between body tag.

Output :- Hello World

2. JavaScript use between head tag in html :

Example to use javaScript between head tag in html.

Output :

3. External JavaScript file :

We can create external JavaScript file and embed it in many html page. If you want to run the same JavaScript on several pages in a web site, you should create an external JavaScript file, instead of writing the same script over and over again.

message.js

index.html

Tagged : / / / / / / / / / / /

JavaScript : Introduction

JavaScript :

  • JavaScript is used to create client-side dynamic pages.
  • JavaScript (js) is a light-weight object-oriented programming language.
  • JavaScript is not a compiled language, but it is a translated language.
  • The JavaScript Translator (embedded in the browser) is responsible for translating the JavaScript code for the web browser.
  •  JavaScript, users can build modern web applications to interact directly without reloading the page every time.
  • databases such as CouchDB and MongoDB uses JavaScript as their scripting and query language.

Features of JavaScript :

There are following features of js :-

  • Object-Centered Script Language
  • Light Weight and delicate
  • Interpreted language
  • Case Sensitive format/language
  • Ability to perform In Built Function
  • Statements Looping
  • Client edge Technology
  • Validation of User’s Input
  • Else and If Statement
  • It uses prototypes rather than using classes for inheritance.
  • It is supportable in several operating systems including, Windows, macOS, etc.
  • It provides good control to the users over the web browsers.

Application of JavaScript

JavaScript is used to create interactive websites. It is mainly used for:

  • Client-side validation
  • Manipulating HTML Pages
  • User Notifications
  • Dynamic drop-down menus
  • Displaying date and time
  • Displaying pop-up windows 
  • Alert dialog box
  • Confirm dialog box
  • Prompt dialog box
  • Back-end Data Loading
  • Presentations
  • Server Applications
  • Displaying clocks etc.

JavaScript Example :

Output :-

Welcome to JavaScript

Hello JavaScript by JavaScript

Tagged : / / / / / / / / / / / / / /

Top programming languages in the world & their courses and certifications?

The world is turning into smarter day by day with the quick development of Automation, computing, Blockchain, etc. And at the middle of it, somewhere, are programming languages. In fact, Labour Statistics have expected a 21% growth for programming jobs within the returning decade, which is quite 4x the common for all occupations. however attempting to start out out with programming is a frightening escapade, particularly for professionals with no previous expertise. thus if you’re one who cannot decide wherever to start, don’t worry as a result of we’ve got you coated. the following article aims to grant you a fast examine the highest Programming Languages within the world & their courses and certifications?

Java

Owned by the Oracle Corporation, Java is one of the oldest, most typical, in-demand programming languages in use these days. Well, think about a number of your favorite internet apps and games. It’s extremely probably that Java plays an enormous role within the code that creates their work. Another necessary factor that has kept Java’s magic intact among internet development corporations is its independence from platforms. This helps developers to basically “write once, work anywhere”(WORA). Java is everyplace and also the demand for sturdy developers is virtually high.

How does it work?

In Java, programs don’t seem to be compiled into practicable files; they’re compiled into bytecode (as mentioned earlier), that the JVM (Java Virtual Machine) then executes at runtime. Java source code is compiled into bytecode after we use the javac compiler. The bytecode gets saved on the disk with the file extension.

Reasons for Demand:

  • With its presence in almost 3 billion devices, Java’s new frameworks such as Spring, Struts, and Hibernate have also become very popular.
  • It is favored by enterprises, with roughly 90 percent of Fortune 500 companies use Java for building applications and back-end systems.
  • Java is highly recognized for its scalability and portability across multiple platforms from mainframe data centers to smartphones.
  • With millions of users across the globe, the popular users of Java include Barclays, HCL, Capital One, etc.
  • Forms the base for and is used in a multitude of domains including mobile application, web development, system programming, and big data.
  • Its powerful features include strong memory management, high performance, backward compatible and top-notch security.

Golang

Developed by the technical school big Google itself, Go is one of the newest players within the programming platform. it’s an open-source language that produces it simple to form easy, secure, and productive computer code. It combines the most effective aspects of useful and object-oriented programming, also as options a valuable set of intrinsical development tools.

How does it work?

Go was originally designed for programs associated with networking and infrastructure. it absolutely was meant to switch widespread high-performance server-side languages like Java and C++. Today, Go is used for a spread of applications like cloud and server-side applications, DevOps, command-line tools, and far additional.

Reasons for Demand:

  • Popular projects like Kubernetes, Docker, Hugo, Hyperledger Blockchain, and Ethereum are developed using Golang.
  • The language is straightforward to grasp even for the new programmers while being extremely powerful at the same time.
  • Supports multithreading at large and is hence used by a lot of companies that rely heavily on distributed systems.
  • Go has been optimized by Google to be incredibly efficient with memory and has blazing fast speed.
  • It provides high performance like C/C++ and has efficient concurrency handling like Java.
  • It is widely used in startups and some of the companies that use the language are Walmart, Springboard, Siemens, Dell.

TypeScript

TypeScript might be a superset of the JavaScript language that has a single open-source compiler and is developed within the main by one trafficker (Microsoft.) The goal of the matter is to help catch mistakes early through a sorting system and to make JavaScript development further economical.

How does it work?

TypeScript works by adding increased syntax to JavaScript so transforming it to JavaScript when the typescript compiler will its own checks. It does not modification JavaScript’s kind of system. Instead, it adds a lot of checks to it.

Reasons for Demand:

  • TypeScript simplifies JavaScript code, making it easier to read and debug.
  • TypeScript gives us all the benefits of ES6 (ECMAScript 6), plus more productivity.
  • TypeScript can help us to avoid painful bugs that developers commonly run into when writing JavaScript by type checking the code.
  • TypeScript is a modern programming language loved by engineers for making web development a lot easier.
  • You can use TypeScript everywhere instead of JavaScript, as it compiles to regular JS code. That’s another reason for its demand.

Scala

Scala could be a programming language used for practical programming and powerful static systems. It’s object-oriented and runs on JVM. It’s the aptitude to interoperate with existing Java code and libraries. It’s powerfully thought of to be a static kind of language and doesn’t have an idea of primitive information.

How does it work?

The compiler in Scala works during a similar fashion because of the Java compiler. It gets the source code and generates Java byte-code which will be dead severally on any commonplace JVM (Java Virtual Machine). Scala could be a statically typed language. Scala will execute Java.

Reasons for Demand:

  • Scala programming language variables are immutable and can be easily overloaded in Java. In addition to this, it also offers to adopt new languages like Python, Ruby, etc. to implement functional programming.
  • Scala is a language that is inherently more expressive than Java. The developers who learn Scala after Java find it easier and interesting to write code in Scala. To get the beauty of this language in comparison with Java.
  • A developer needs to be in demand always. The main reason or use of Scala is a better growth and job. Learning Scala will increase your demand and will make you even more marketable. Many companies like Twitter, LinkedIn, Foursquare, etc are using Scala.
  • Scala can be said as a language that is growing fast and lots of programmers going to join the Scala bandwagon. Even developers who know Java are now moving to learn Scala. There are many new libraries and frameworks that are being built on application of Scala.
  • A Java programming finds it difficult to learn any functional language. uses of Scala is easy due to its object-oriented functionality. Scala has clean syntax, nice libraries, good online documentation, and lots of people in the industry using it.

JavaScript

Along with HTML and CSS, Javascript is that the programming language that engineered the internet. So, it’s a fairly huge deal. Universally referred to as the language of internet developers, javascript could be a feature-rich object-based scripting language that includes asynchronous event handling and crisp syntax, it’s found widespread use within the field of internet development. What started off as an easy client-side scripting language, is currently a highlight inside the net development community that includes multiple frameworks for each backend and frontend development.

How does it work?

JavaScript is what’s known as a Client-side Scripting Language. within a standard website, you place some JavaScript code See however sites Work for details on sites. once the browser loads the page, the browser features a constitutional interpreter that reads the JavaScript code it finds on the page and runs it.

Reasons for Demand:

  • In extension to absolute JavaScript, various popular libraries and frameworks make JavaScript development easier.
  • Most accessible supporting technologies related to JavaScript are JSON, jQuery, Angular, React (JS Library), etc.
  • Fundamentally a front-end language, it can also be practiced on the server-side throughout Node.js to create scalable network applications.
  • Majority of tech giants like Google, Facebook, SAP, Dell, Accenture, etc rely on Javascript to design interactive web pages and dynamically display content to users.

PHP

PHP is used by 79% of all the websites whose server-side programming language we all know. it’s the main used for developing dynamic and data-heavy websites and applications. it’s been the cornerstone of the net for a protracted time. PHP could be an easy, fast, and platform-independent general programming language with over 631,000 repositories on GitHub.

How does it work?

The PHP software system works with the webserver, which is that the software system that delivers sites to the planet. after you A URL into your net browser’s address bar, you are causation a message to the webserver at that URL, asking it to send you an HTML file. Your browser reads the HTML file and displays the online page.

Reasons for Demand:

  • PHP is used by 79.0% of all the websites whose server-side programming languages are known.
  • PHP is simple, fast and platform-independent.
  • It is 631k repositories on GitHub and has a community of 5.9M to back it up.
  • Companies that have publicly declared usage of PHP include Facebook, Yahoo, Wikipedia.

AngularJs

AngularJS could be a client-side JavaScript MVC framework to develop a dynamic internet application. It extends the flexibility of HTML by adding intrinsical attributes and parts and additionally provides a capability to form custom attributes victimization easy JavaScript.

How does it work?

AngularJS could also be a structural framework for dynamic net apps. It permits you to use hypertext markup language as your model language and permits you to extends HTML syntax to specify your application’s elements clearly and compactly. AngularJS’s information binding and dependency injection eliminate a lot of the code you’d otherwise need to write.

Reasons for Demand:

  • Modularity is one of the prime reasons why AngularJS is popular among web developers.
  • AngularJS recognizes the need to create an additional module so that it can be combined with other developed application modules.
  • It allows and enables web developers to create multiple modules for a single web application.
  • AngularJS is one of the skills unique to this job, along with React. js, Code. js, Javascript, and CSS.
  • Today, AngularJS is a leading framework for building dynamic, single-page web applications (known as SPAs), including ones like PayPal and Netflix.

NodeJs

Node. js is primarily used for non-blocking, event-driven servers, because of its single-threaded nature. It’s used for ancient websites and back-end API services time period was designed with the period of time, push-based architectures in mind.

How does it work?

Node. js is the JavaScript runtime environment which is based on Google’s V8 Engine with the help of Node, Js we can run the JavaScript outside of the browser, js is that it is single-threaded, based on event-driven architecture, and non-blocking based on the I/O model.

Reasons for Demand:

  • A Single Language for All Layers. Another key benefit of Node.
  • It can be Hosted Anywhere.
  • It’s lightning Fast. Node.
  • It is JavaScript Everywhere. One of the biggest reasons why Node.
  • It is Lightweight. Typically, Node.
  • High Performance.
  • It is Easy to Modify and Maintain.

Conclusion

In this article, we have listed the top most popular programming languages to learn. Now, it’s your choice where you want to land your career or choose the right programming language for you, If you wanna learn then i would suggest you check out DevOpsSchool it is a great platform for learning. Get an insight to all the details we mentioned, and choose accordingly. So, make sure you should hold a good command on a specific language you choose for programming.You’ll even also join our Online and Classroom Programs.
And that concludes my list of the Top Programming Languages. Hope this article proved useful to you.

Thank you!

Tagged : / / / / / / /

Tutorial for Polymorphism in OOPS

What is Polymorphism?

Polymorphism, as its name implies, comes in a variety of forms. OOP allows for the use of a variety of techniques I. Simply expressed, they have to do with how methods are used, and how different methods operate for different objects. Method Overriding and Method Overloading are two ways that polymorphic methods allow for different actions to be done.

The benefits of Polymorphism are:

  • Objects of different types can be passed through the same interface
  • Method overriding
  • Method overloading

Method Overriding:- Overriding is used in the polymorphism of runtime. By overriding a parent class’s method, a child class can implement a different method. In the case of our dogs, we may prefer a specific type of bark that is distinct from the generic type of dog (TrackingDog).

Example:-

TrackingDog’s overriding the bark() method

Method Overloading:- Overloading is used at the polymorphic build time. Although methods and functions may have the same name, the call method has its own set of arguments. Different results may be obtained depending on the number of parameters entered.

Example:- There are no parameters supplied to the updateAttendance() method. The count will be added one day. When the updateAttendance(4) argument is used, the x xupdateAttendance(x) parameter is used, and four days are added to the total.

Tagged : / / / / / / / / /

Tutorial for Abstraction in OOPS

What is Abstraction?

Basics of Computation Theory. What is "abstraction"? Abstraction unifies  multiple and different objects into one concept  describes the common  properties. - ppt download

Abstraction in OOP allows information/access about how codes are applied to be concealed, allowing just the required access. These details may be found in the object definitions. A famous example is the counting approach that works with list items. One thing to keep in mind is that, given the same OOP concept, all Python I data types and structures are objects. In this sense, a list is a class that has methods for completing tasks.

What is Abstraction in OOPS? - JournalDev

What is the Function of Abstraction?

Abstraction use simpler high-level instruments to get access to a complex object:

  • Using simple things to represent complexity
  • Hide complex details from user
JavaScript ES7 OOP. Abstraction. Class. #1 - YouTube

Abstraction also serves a significant security role. We only present selected data items and provide data access via classes and methods to protect the data from being exposed. In the case of an automobile, an open gas tank would make it impossible to continue driving.

There are some benefits of abstraction which is mention below:

  • Simple, high level user interfaces
  • Complex code is hidden
  • Security
  • Easier software maintenance
  • Code updates rarely change abstraction

Tagged : / / / / / / / / /

Complete guide of JavaScript Certification courses, tutorials, and training

Tutorials

JavaScript may be a lightweight, taken artificial language. It’s designed for making network-centric applications. It’s complimentary to and integrated with Java. JavaScript is incredibly straightforward to implement as a result of its integration with a mark-up language. It’s open and cross-platform.

What is JavaScript?

JavaScript is the Programming Language for the Web, JavaScript is a programming language commonly used in web development. JavaScript can inform then adjust together HTML and CSS. JavaScript can calculate, operate and validate data. This means JavaScript purposes can run after a webpage has loaded without interactive using the server.

Why it is used?

JavaScript is a text-based programming language used both on the client-side and server-side that allows you to create web pages interactively. Where HTML and CSS remain languages that provide structure then style to web pages, JavaScript provides web pages communicating elements that include a user.

How does JavaScript work?

The way JavaScript works is interesting. Inside a communal Web page, you place certain JavaScript code ‘Understand How Web Pages Work used for details on Web pages. While the browser loads the page, the browser has a built-in interpreter that reads the JavaScript code it finds on the page then runs it.

Advantages of JavaScript:

The advantages of using JavaScript are the following:

  • Immediate feedback to the visitors − they do not have to wait for a page reload to see if they have been unable to remember to enter something.
  • Richer interfaces − you be able to use JavaScript to include such things as drag-and-drop components and sliders to give a Rich Interface to your site visitors.
  • Less server interaction − you be able to verify user input before sending the page off to the server. This saves server traffic, which means not as much load on your server.
  • Increased interactivity − you be able to make interfaces that respond while the user hovers over them with a mouse or else activates them via the keyboard.

Why is JavaScript so important?

JavaScript could be a programing language used principally by net browsers to create a dynamic then human action data used for the user. Most of the needs and applications that build the web indispensable to trendy life stay coded in sure sorts of JavaScript.

Features of Java Script:

  • JavaScript provides HTML originators a programming tool – HTML authors remain usually not programmers, but then JavaScript is a scripting language using a very simple syntax; Nearly someone can put small ‘snippets’ of code into their HTML pages.
  • JavaScript be able to put dynamic text into an HTML page – A JavaScript statement like this: document. Write (“<h1>” + name + “</h1>”) can write a variable text into a HTML page.
  • JavaScript be able to react to events – A JavaScript be able to be set to implement while something occurs like as soon as a page has to overload otherwise once a user clicks on an HTML element.
  • JavaScript be able to read and write HTML elements – JavaScript be able to read then change the content of an HTML element.
  • JavaScript be able to be used to validate data – JavaScript be able to be used to validate form data before it is submitted to a server. This protects the server from extra processing.
  • JavaScript be able to be used to detect the visitor’s browser – JavaScript is able to be used to detect the visitor’s browser, and depending on the browser – load another page specifically designed for that browser.
  • JavaScript be able to be used to create cookies – JavaScript is able to be used to store and retrieve info on the visitor’s computer.

What is JavaScript Framework, and Why Use One?

A coding framework remains an inspiration during which code as long as general practicality be ready to be by selection modified through different user-written code. JavaScript framework could be a submission framework written in JavaScript wherever the programmer’s square measure ready to influence the needs then use them used for his or her quality.

Frameworks stay a lot of adjustable for the planning of internet sites, then hence, most web site developers like them. JavaScript frameworks stay a sort of tool that creates operating by JavaScript easier and power tool. These frameworks still build their potential used for the computer programmer to code the appliance as per a tool receptive. This willingness is up until currently a further reason why the JavaScript frameworks stay quite widespread whereas it originates to the question of employing a high-level machine language. In 2021 let’s have a glance at the simplest JS Frameworks.

JavaScript Framework are:

1. Angular

One of the most powerful, effective, and open-source JavaScript frameworks is Angular. Google operates this framework then is applied to use meant for developing a Single Page Application (SPA). It extends the HTML into the application and interprets the qualities to perform data binding.

2. React

Formed using Facebook, the Respond framework has earned popularity within a short period. It remains used to develop then function the dynamic User Interface of the web pages with high inward traffic. It creates the use of a computer-generated DOM, and hence, the integration of the same with any application is more straightforward.

3. Vue.js

However developed in the year 2016, this JavaScript framework has previously prepared its way into the market then has verified its worth through offering several features. Its dual integration way is one of the most attractive features used for making high-end SPA or Single Page Applications. It is an abundant dependable platform for developing cross-platform.

4. Ember.js

The intro of Ember.js to the software market was in 2015, and since then, it has increased admiration by its wide application area. The features of Ember.js provision two-way data binding and hence, begin a dependable platform for handling difficult User Interfaces. Popular websites like Netflix, Linked In, Nordstrom, and many more use the Ember.JS platform for their websites.

5. Meteor

Meteor’s application area (aka Meteor.js or MeteorJS) work for the name itself since it is diverse as it covers virtually the important portion of the software development. Usages of this framework comprise significant zones like back-end development, management of the database, business logic, and version of the front-end.

6. Mithril

Mithril may be a client-side JavaScript framework that’s used primarily in developing Single Page Applications. As there stay no by-product functions from a base category, the framework’s implementation is additionally easy. It’s tiny (< 8kb gzip), quick and provides routing and XHR utilities out of the box. It’s a number of options almost like react.

7. Node.js

Node.js could be a server-side JavaScript run-time atmosphere, which works on cross platforms and is an ASCII text file. The framework is capable of driving asynchronous I/O with its event-driven design. It works within the JavaScript Runtime atmosphere and shows JAVA’s similar properties like threading, packaging, o forming loops.

8. Polymer

The chemical compound is associated with the ASCII text file JavaScript library developed by Google, which might produce the website’s components while not reaching a fancy level. Also, it supports each unidirectional and two-way knowledge binding, thence creating an additional intensive application space.

9. Aurelia

Aurelia framework is that the latest version of JavaScript, which might be accustomed implement any interface. it’s ensuing generation of the framework for developing way more strong websites. The framework of Aurelia will extend the hypertext mark-up language for varied functions, as well as knowledge binding. Also, its trendy design ensures that the aim of toll is for interpretation client-side and server-side at a time.

10. Backbone.js

It is one among the foremost in style JavaScript frameworks. It’s easy to know and learn. It is wont to produce Single Page Applications. The event of this framework involves the thought that each one the server-side functions should flow through AN API, which might facilitate accomplish advanced functionalities by writing less code.

What is the scope in JavaScript?

The scope may be a policy that manages the supply of variables. A variable outlined within the scope is accessible solely at intervals that scope, however inaccessible outside. In JavaScript, scopes square measure created by code blocks, functions, modules.

What are the benefits of “JavaScript” Certification?

Certifications continually play an important role in any profession. You will realize some PHP professionals, WHO can tell you that certifications don’t hold abundant worth. This certification demonstrates a human ability to get advanced searches, reports, and dashboards with JavaScript’s core software system to induce the foremost out of their information.

JavaScript course:

This course was developed to show you the key JavaScript syntax and options you will need to be told as a booming internet developer. a number of the foremost topics that we’ll cowl embrace are the newest JavaScript syntax enhancements, organizing your code into categories and modules, communication with internet services, error handling, and security, and far additional. By the tip of this course, you will acumen to line up JavaScript development surroundings and build nice JavaScript applications for the net.

Conclusion

JavaScript could be a rattling technology to use on the net. It’s not that onerous to find out and it’s terribly versatile. It plays nicely with alternative internet technologies — like hypertext mark-up language and CSS — and might even move with plugins like flash.

If you are want to learn JavaScript in-depth, DevOpsSchool is one of the best for the Complete JavaScript Course would be a great stepping stone for you.

Thank You!

Tagged : / / / / /

How to Export Html Table to Excel Sheet using JavaScript

Steps to Export HTML Table Data to Excel using JavaScript

  1. HTML Table Data:
  2. JavaScript Code:

1. HTML Table Data

Export HTML data in Excel, even before we have to load some data into an HTML table. So here we have to make fetch employee table data and load it in an HTML table with table columns like name, address, gender, designation, and age. Here we have created an HTML table with id employee_data. So this id we will use for fetch this HTML table data in JavaScript code. Under this HTML code, we have made one button tag with id export_button, so when use has clicked on this button, then HTML table data will be download in Excel file format without refresh of a web page using JavaScript.

2. JavaScript Code

In this tutorial, we have to use SheetJS JavaScript Library to export HTML table data to Excel using JavaScript. So first we have to include the following SheetJS library link at the header of this HTML web page.

In the JavaScript code part, first we have created the html_table_to_excel(type) function. This function has used sheetJS library function and convert or write HTML table data to excel format and download it in a browser without refreshing the web page.

Once a function is ready then we have to call html_table_to_excel(type) function on the button click event, so for the trigger button click event, we have to use the addEventListener method. So when a user has clicked the button the html_table_to_excel(type) function is called with the xlsx file type. Then it will download the HTML table data in .xlsx format Excel file in the browser without having to refresh a Web page on the client-side.

Tagged : / / / /

How to Display Excel Data in HTML Table using JavaScript?

In this tutorial, you can find how to read excel files using javascript and display excel sheet data on web pages in HTML table format using javascript. In the previous, one of our tutorials, in which we have already seen how to convert HTML table data to Excel files using the SheetJS library. Now in this tutorial also we will be using the SheetJS JavaScript library and by using the JavaScript library, we will convert the Excel file data into an HTML table and display it on the web page.

First, we have to include the Bootstrap Stylesheet and SheetJS library link at the header of our HTML page.

After this under this HTML page, we have to create one file tag for select file excel from the local computer.

And below this file, we have to create one division tag to display excel sheet data on the web page in HTML table format.

Next, we have to move on to writing JavaScript code, so first store file tag property under one variable.

Next, we need to write the JavaScript code on the change event, so when the user has selected a file from the local computer using the file tag, the JavaScript code should be executed.

excel_file.addEventListener(‘change’, (event) => { });

Under this change event code first, we want to check the selected file format .xls or .xlsx. If the selected file is not an Excel file then it will display an error on the web page, and if the selected file is Excel then it will proceed to display the Excel file data on the web page.

After a check, the validation error, now read the file using the FileReader object. Here file must be read ads ArrayBuffer bypassing the file object using event.target.files[0].

IF the selected file is a proper excel file then we need to convert what we have got from the FileReader object to Unit8Array object by passing Filereader result into Unit8Array constructor.

Next, we have pass this Unit8Array data in SheetJS read() function, and it will return the selected excel workbook object.

After getting the workbook object, next we have to get the sheet name of the selected excel file. So here SheetNames variable will return sheet name in array format.

Once we have to get the sheet name, now we want to get the first sheet data in JSON format, so we can get by SheetJS sheet_to_json() function by passing the workbook first sheet name.

Once we have to get the first sheet data in JSON format, next we have to simply write JavaScript code and convert that JSON data into an HTML format and display it under division tag with id excel_data. So it will display excel file data on the web page in HTML table format.

So once you have followed all the above steps then you can check output in the browser. So when we have selected an excel file then it will display excel sheet data on the web page in HTML table format without a refresh of the web page. So in this tutorial, we have seen how to convert Excel files to HTML tables at the client-side by using the SheetJS JavaScript library at the client-side. You can find the complete source code here.

Tagged : / / /

How does the JavaScript Promise work?

Promise

A Promise is an object representing the eventual completion or failure of an asynchronous operation. A JavaScript Promise object contains both the producing code and calls to the consuming code. It can be used to deal with Asynchronous operations in JavaScript.

Promise State:-

Pending – Initial State, Not yet Fulfilled or Rejected
Fulfilled/Resolved – Promise Completed
Rejected – Promise Failed

How Promise works

  • A pending promise can either be Resolved with a value or Rejected with a reason (error).
  • When either of these options happens, the associated handlers queued up by a promise’s then method are called.
  • A promise is said to be settled if it is either Resolved or Rejected, but not Pending.

Creating Promise

Promise () – A Promise object is created using the new keyword and its constructor. This constructor takes a function, called the “executor function”, as its parameter. This function should take two functions as parameters. The first of these functions (resolve) is called when the asynchronous task completes successfully and returns the results of the task as a value. The second (reject) is called when the task fails and returns the reason for failure, which is typically an error object.

Syntax:- Promise (executor)

A JavaScript Promise object contains both the producing code and calls to the consuming code.

Function Returning a Promise

then( ) Method

The then() method returns a Promise. It takes up to two arguments: callback functions for the success and failure cases of the Promise. As then the method returns a Promise so we can do method chaining.

Syntax:- then(onResolved, onRejected)

onResolved – A Function called if the Promise is fulfilled. This function has one argument, the fulfillment value.

onRejected – A Function called if the Promise is rejected. This function has one argument, the rejection reason.

Promise

Chaining

The then method returns a Promise which allows for method chaining. If the function passed as a handler to then returns a Promise, an equivalent Promise will be exposed to the subsequent then in the method chain.

catch () Method

The catch() method returns a Promise and deals with rejected cases only. It behaves the same as calling then(undefined, onRejected). In fact, calling catch(onRejected) internally calls then(undefined, onRejected).

The catch method is used for error handling in promise composition. Since it returns a Promise, it can be chained in the same way as its sister method, then()

Syntax:- catch(callback)

Where the callback is a function called when the Promise is rejected. This function has one argument error – The rejection error.

catch () Method

finally () Method

The finally() method returns a Promise. When the promise is settled, i.e either fulfilled or rejected, the specified callback function is executed. This provides a way for code to be run whether the promise was fulfilled successfully or rejected once the Promise has been dealt with.

This helps to avoid duplicating code in both the promise’s then() and catch() handlers.

Syntax:- finally(callback)

finally () Method

Chaining

Tagged : / / / /