Addition in Javascript

An Addition Program in Javascript. Using several JavaScript techniques, you will learn how to add two numbers and display their sum in this example. In JavaScript, you can add numbers by putting a + sign between them. You can also execute addition using the following syntax: var x+=y; JavaScript uses the “+=” operator to add the variable on the right side of the operator to the variable on the left.

Addition of Two Numbers in JavaScript

const a = 4;
const b = 3;
const sum = a + b;
console.log(‘The sum of ‘ + a + ‘ and ‘ + b + ‘ is: ‘ + sum);



Uses of Addition in Javascript

The + symbol is used to denote addition. An addition sentence is a mathematical statement that depicts the sum of two or more values. Addends are the numbers that are added, and the total is the result of addition in javascript.

Addition of Two Numbers Entered By User in JavaScript

const a = parseInt(prompt(‘Enter first number’));
const b = parseInt(prompt(‘Enter second number’));
const sum = a + b;
console.log(`The sum of ${a} and ${b} is ${sum}`);



Prompt in JavaScript

In JavaScript, the prompt() method is used to display a prompt box that asks the user for input. It’s usually used to get the user’s input before entering the page. It is possible to write it without the window prefix. To proceed, we must click “OK” or “Cancel” when the prompt box appears.

prompt() opens a new window. prompt() tells the browser to show a dialogue with an optional message asking the user to enter some text and to wait until the user submits the text or closes the dialogue. This is sample program for Addition in Javascript for beginners.

Const in JavaScript

The keyword ‘const’ in JavaScript denotes that the identifier cannot be reassigned. Immutable values are not to be confused with immutable values. A ‘const’ object, unlike truly immutable datatypes like those created by Immutable. js and Mori, can have its properties changed.

A read-only reference to a value is created by using the const declaration. It doesn’t mean the value it carries is unchangeable; it merely means the variable identification can’t be changed. This is sample program for Addition in Javascript.

Console.Log in JavaScript

The JavaScript console log function is primarily used for code debugging because it prints the output to the console. To open the browser console, right-click on the page and select Inspect, then Console. 

In JavaScript, the console. log() function prints any variables that have been previously defined in it, as well as any messages that need to be displayed to the user. The log() function in the console writes a message to the debugging console, such as Webkit or Firebug. Nothing will appear on the screen in a browser. It sends a debugging message to a console.