GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Find us on Discord!
  • Home
  • Spring AI
  • Claude & Copilot
  • DevOps
  • Agile & Scrum
  • Certification
  • Register
  • Sign In

This view

  • Original page
  • New address

GeezerVison is showing www.theserverside.com — JavaScript

Object-Oriented Programming Explained and Defined (OOP)

Can you explain object-oriented programming to me like I'm 5 years old? Probably not. But here's a straightforward explanation of what OOP is ...

spring

Build a Spring Boot 4 File Uploader with Java 26

Use Spring MVC MultipartFile, Java Path APIs and the browser fetch API to upload files asynchronously and save them safely on the server.

Spring

How Java Constructor Overloading Works

See how overloaded constructors provide flexible initialization and how the this() method reduces duplicate code in a Java class.

Spring

Understanding Brackets, Braces, and Parentheses in Code

Explore the correct terminology and common programming uses for round parentheses, square brackets, and curly braces.

Spring

Set Up the Java 21 JDK on Windows

Follow the essential steps to download Java 21, configure Windows environment variables, update PATH, and confirm that the JDK is working.

Spring

Opening and running Java JAR files

Learn how JAR files relate to ZIP archives, how to extract their contents, and how to run them with Java commands.

Spring

Running Java JAR Files Across Desktop Platforms

This video explains how to execute JAR files, use the java and jar commands, inspect archives, and resolve main-class errors on Windows, Mac, ...

Spring

PascalCase Naming Convention Explained

Learn how PascalCase works, how it differs from camel, snake, and kebab case, and how Java developers apply it to code.

Spring

A Practical Guide to HTTP Verbs in REST APIs

Understand what each major HTTP method does, how safe and idempotent operations differ, and which verbs REST API developers use most often.

Spring

Set JAVA_HOME on Windows Using Three Simple Approaches

Configure the Java home directory with an installer, Windows environment settings, or the command line, then echo the variable to confirm it w...

Spring

Installing the Java JDK on Windows

Follow five practical steps to download the JDK, configure Windows environment variables, and confirm Java works from the command line.

Spring

Understanding Java Array Length, Capacity, and Loops

See how to read an array's length, define its fixed size, compare arrays with ArrayList and String, and use length in loops.

Spring

Understanding PUT and POST HTTP Methods

Compare how PUT and POST handle resources, URLs, payloads, idempotence, creation, updates, and other REST API operations.

Spring

11 Programmer Jokes for Java Developers and Tech Teams

Share these playful programming jokes, complete with explanations of the Java, Linux, recursion, and developer references behind each punchline.

Spring

Install Java 21 and configure JAVA_HOME on Ubuntu

Use apt to install the JDK, verify Java 21 on Ubuntu, and configure the JAVA_HOME environment variable for system-wide use.

Spring

JavaScript Spring

JavaScript is a programming language that started off simply as a mechanism to add logic and interactivity to an otherwise static Netscape browser. In the years since its introduction, it has not only supplanted a variety of other competing languages and technologies to become the standard for browser-based programming, but it has also expanded beyond the client space to become a dominant language on the server side, as well.

What JavaScript can be used for

The Hyper Text Transport Protocol, or HTTP, was designed to do exactly what the name implies, which is to transport HTML text across a network for viewing. But the problem with HTML is that it is completely static, providing no capabilities to implement logic.

Basic features we currently take for granted, such as input validation, autocorrect, progress bars or causing a graphic to change during a mouse rollover, would all be impossible for a browser to perform without some type of scripting capability. As a result, when the web first rose to prominence, every vendor in that space provided some mechanism to make HTML web pages more interactive.

Alternatives to JavaScript

Microsoft promoted a competitor to JavaScript named VBScript, along with plug-in technologies, such as ActiveX Data Object (ADO). Sun Microsystems promoted Java applets that were cross-platform and could be used in any browser.

Many other technologies came and went as the internet matured. In the end, JavaScript won the battle for popularity, and it is the only client-side scripting technology supported by the Chrome, Firefox, Safari and Internet Explorer browsers.

JavaScript is an interpreted language, as opposed to compiled languages, such as C++ and Java. This means that the code written in JavaScript does not go through an intermediary compilation stage in which the source code is transformed into machine language that is easy for a CPU to process.

Instead, JavaScript is interpreted on the fly by the computer processing it. Because JavaScript code is not packaged in a CPU-friendly form, such as Java bytecode or a binary executable, program execution can be slower than a comparable program written in Scala or F#. However, modern JavaScript engines are highly optimized, and inefficiencies are rarely noticeable when using modern hardware.

Short note on JavaScript versus Java

Given the first four letters of the name, a misconception exists that JavaScript and Java are similar. While it is true that Java and JavaScript share some very basic syntax elements, such as the use of semicolons to terminate a statement, the use of curly braces to delineate code block, and similar constructs to create looping and iterative structures, the similarities end there.

The two languages do not originate from the same vendor, the two languages are not maintained by the same consortium, and fundamental language features, such as object orientation and strong typing, are major instances in which the two differ. Java and JavaScript are two very separate and distinct programming languages that should not be confused with one another.

Basics of JavaScript programming

HTML provides a special <SCRIPT> tag that enables developers to embed JavaScript within the markup of the page.

Variable declaration using the var keyword in JavaScript is very straightforward and does not involve a complex set of initialization rules as one might see in Java or C++. JavaScript is known as an untyped language, which means that variables can take on a variety of different forms as a program executes.

For example, in the following program, a variable named greeting is declared and is initialized to a text string. But, on the next line, the greeting variable is assigned to an integer value of 10. A new variable named product is then initialized to the value of the greeting variable multiplied by itself.

var greeting = 'Hello World';
greeting = 10;
var product = greeting * greeting;

Using JavaScript's var keyword to declare variables

Because it is permissible for a variable named greeting that is created as a text string type String to change on the fly to a variable of type integer, JavaScript is known as a weakly typed language. In a strongly typed language like C++ or Java, this type of variable transformation would trigger a compilation error.

JavaScript's let vs. var

Historically, the var keyword has been used to instigate the declaration of a variable. However, when using the var keyword, the variable can end up having a broader scope than was originally intended, which can cause conflicts with other parts of the code that might declare a similarly named variable.

Version 6 of the ECMAScript standard introduced the let keyword for declaring variables. Both var and let share the same syntax, but variables declared using JavaScript's var keyword are scoped to the function in which they are declared, whereas the JavaScript let keyword keeps the variable scoped to the block in which it was declared.

{
  let greeting = 'Hello World';
  greeting = 10;
  let product = greeting * greeting;
}

JavaScript functions versus methods

The content of the <SCRIPT> tag can either be code to be invoked as soon as a user encounters the <SCRIPT> tag or it can contain JavaScript functions.

JavaScript functions are analogous to what other languages would call methods. These JavaScript functions contain code that can be triggered by a browser-based event, such as a mouse click, page load, form submission or keystroke. It is also common to have one JavaScript function invoke another to perform supplemental work.

Example of JavaScript code

The following is a simple example of a rock-paper-scissors application coded using HTML and JavaScript. The <SCRIPT> tag contains a JavaScript function called playRoshambo, which is triggered by the onclick event of the user clicking on an anchor link that contains the text paper. The result of playing the game is displayed within the <div> tag named results.

 <script>
 playRoshambo = function(clientGesture) {
   //server always chooses rock
   if (clientGesture=='rock') {
     result = "tie";
   }
   if (clientGesture=='paper') {
     result = "win";
   }
   if (clientGesture=='scissors') {
     result = "lose";
   }
   document.getElementById('results').innerHTML = result;
 }
 </script>

 Which one will it be?<br/>
 <a href="#" onclick="playRoshambo('paper')"> paper </a>
 <div id="results"></div>

Modern JavaScript libraries

The basic JavaScript engine that comes packaged with a modern browser only provides a basic and rudimentary set of APIs for software development. To perform complicated tasks, such as implementing an Ajax-based request-response cycle or even performing advanced DOM parsing or string manipulations, a great deal of code needs to be written.

Further complicating the task of writing code to achieve common yet complex programming tasks is the fact that there are differences between each of the major vendors in terms of which versions of JavaScript they implement, as well as how bug-free those implementations are.

To address the differences between browsers while at the same time providing prepackaged code for performing very common tasks, JavaScript libraries have become a mainstay of browser-based UI development. The most popular JavaScript library in use today is jQuery, while competitors such as Prototype and Dojo remain quite popular.

Shortcomings of JavaScript

Two common criticisms of JavaScript is the fact that it is weakly typed and that it is not an object-oriented language. Software developers tend to prefer strongly typed object-oriented languages because these features tend to accelerate software development while also helping to maintain a high degree of software quality.

However, because JavaScript has become the de facto language of internet browsers, being able to write high-quality, bug-free code has become a priority for many members of the software development community.

As a result, new languages, such as TypeScript, have emerged that are both strongly typed and object-oriented. TypeScript looks very much like JavaScript, although it enforces strong typing and provides features for developing in an object-oriented manner. TypeScript is also a compiled language, as opposed to JavaScript, which is interpreted.

However, unlike Java or C++ where the source code is compiled into bytecode or binary, TypeScript compiles into pure JavaScript that can be optimized based on the target browser.

About JavaScript frameworks

A big industry trend in UI design is to push as much logic, processing and state management onto the client as you can and to interact with the server through lightweight RESTful APIs and web services. This has led to the development of full scale JavaScript frameworks that control all the aspects of client-side presentation, often pushing a single-page interface (SPI) user experience.

Popular frameworks in this space are Angular, React and Ember, with these frameworks often leveraging compiled JavaScript languages, such as TypeScript and JavaScript libraries like jQuery for logic and Handlebars.js or Mustache.js for web page templating.

Completely Certified in 28 Days

Completely Certified in 28 Days

I passed every AWS exam in just 28 days. Here's how you can do it too!

AWS Practice Exams

The Scrum Master Certification Guide

The Scrum Master Certification Guide

Get Scrum Certified Fast. Learn from Darcy. She's @Scrumtuous!

Scrum Master Certification

Claude Certified Architect Practice Exams

Claude Certified Architect Practice Exams

The fastest way to get Claude Architect Certified - Guaranteed!

Claude Certification

Google Cloud Generative AI Leader Practice Exam

Practice with challenging Generative AI Leader questions and prepare for the Google Cloud certification exam.

Skills

Prepare for the AWS AI Practitioner Exam with 35 Challenging Questions

Review realistic practice questions and detailed explanations covering generative AI, Amazon Bedrock, machine learning concepts, and responsib...

Skills

Practice Questions for the ISC2 Certified in Cybersecurity Exam

Review sample questions and answers on cloud governance, access control, cybersecurity principles, and other topics covered by the ISC2 CC cer...

Skills

Test Your Knowledge With CISA Practice Questions

Review explanations for 20 information systems auditing questions spanning governance, controls, cybersecurity, project management, and audit ...

Skills

Practice for the GitHub Copilot Certification Exam

Review 35 challenging questions and detailed explanations on Copilot features, prompting techniques, data handling, administration, testing, a...

Skills

Prepare for the CISM Exam with Practice Questions

Test your understanding of CISM domains through scenario-based questions and explanations focused on governance, risk, security programs, and ...

Skills

Test Your Google Cloud Engineer Certification Knowledge

Work through exam-style questions and explanations on core Google Cloud services, security, networking, storage, Kubernetes, billing, and oper...

Skills

Prepare for the Microsoft Azure Administrator AZ-104 Exam

Review 35 practice questions and explanations covering core Azure administration topics, including compute, storage, networking, monitoring, i...

Skills

Practice Questions for the AWS Solutions Architect Associate Exam

Test your knowledge with AWS architecture scenarios and detailed explanations covering compute, storage, networking, security, databases, and ...

Skills

Prepare for the AWS Data Engineer Associate Exam

Test your knowledge with scenario-based questions and answers across the core AWS data engineering certification domains.

Skills

A Practical Study Plan for the GitHub Copilot GH-300

Learn how to organize your preparation with exam objectives, realistic practice questions, focused Copilot projects, and a structured test-day...

Skills

Prepare for the Google Cloud Associate Cloud Engineer Exam

Use scenario-based practice questions to study Google Cloud IAM, networking, storage, compute, logging, and other Associate Cloud Engineer top...

Skills

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.