Зміст курсу
Introduction to JavaScript (staging)
Introduction to JavaScript (staging)
Number 1/3
Numbers in JavaScript
JavaScript provides us with double-precision floating-point number to deal with the numbers in the code. You don’t need to specifically write int
or float
for declaring integer or floating values, unlike other programming languages.
let totalPlayer=10; console.log(totalPlayer);
+
Operator with Numbers:
+
operator is used in two ways with the number data type.
- Addition:
+
is used for addition when both the operands are numbers, for example.
let firstNumber = 10; let secondNumber = 20; let total = firstNumber + secondNumber; console.log(total);
- Concatenation:
When one operand is a number while the other is a string, the+
operator concatenate them together, for example.
let company = 'Robotech '; let version = 10; let newLaunch = company + version; console.log(newLaunch);
JavaScript NaN and Infinity:
In JavaScript, the number datatype has some exceptions which are called “Special Numeric Values”. The exceptions are:
- NaN:
NaN
stands for Not a Number.NaN
, in JavaScript, is a keyword that is used to check whether the value or variable is not a number.
We getNaN
as a result when we perform arithmetic operations other than+
between a numeric value and a string value, for example.
let numberOfStudent = 20; let greeting = 'Hello'; let total = numberOfStudent - greeting; console.log(total);
- Infinity:
We getInfinity
or-Infinity
, in JavaScript, if the result of a calculation exceeds the largest possible number or the smallest possible number respectively, for example.
console.log("2 / 0 :", 2 / 0) console.log("-2 / 0 :", -2 / 0)
In JavaScript, you can use the isFinite()
function to check whether a value or variable is Finite or not, for example.
let score = 123; let status = 'Test'; console.log(isFinite(score)); console.log(isFinite(status));
Note:
If isNaN()
returns true
, it means that the data type is not a number.
let name = 'Bob'; console.log(isNaN(name));
Swipe to show code editor
A variable named comment
with the assigned value of "hello123"
has been given to you. Your task is to check and print whether the comment
variable is a number or not as well as whether it is Finite or not.
Дякуємо за ваш відгук!
Number 1/3
Numbers in JavaScript
JavaScript provides us with double-precision floating-point number to deal with the numbers in the code. You don’t need to specifically write int
or float
for declaring integer or floating values, unlike other programming languages.
let totalPlayer=10; console.log(totalPlayer);
+
Operator with Numbers:
+
operator is used in two ways with the number data type.
- Addition:
+
is used for addition when both the operands are numbers, for example.
let firstNumber = 10; let secondNumber = 20; let total = firstNumber + secondNumber; console.log(total);
- Concatenation:
When one operand is a number while the other is a string, the+
operator concatenate them together, for example.
let company = 'Robotech '; let version = 10; let newLaunch = company + version; console.log(newLaunch);
JavaScript NaN and Infinity:
In JavaScript, the number datatype has some exceptions which are called “Special Numeric Values”. The exceptions are:
- NaN:
NaN
stands for Not a Number.NaN
, in JavaScript, is a keyword that is used to check whether the value or variable is not a number.
We getNaN
as a result when we perform arithmetic operations other than+
between a numeric value and a string value, for example.
let numberOfStudent = 20; let greeting = 'Hello'; let total = numberOfStudent - greeting; console.log(total);
- Infinity:
We getInfinity
or-Infinity
, in JavaScript, if the result of a calculation exceeds the largest possible number or the smallest possible number respectively, for example.
console.log("2 / 0 :", 2 / 0) console.log("-2 / 0 :", -2 / 0)
In JavaScript, you can use the isFinite()
function to check whether a value or variable is Finite or not, for example.
let score = 123; let status = 'Test'; console.log(isFinite(score)); console.log(isFinite(status));
Note:
If isNaN()
returns true
, it means that the data type is not a number.
let name = 'Bob'; console.log(isNaN(name));
Swipe to show code editor
A variable named comment
with the assigned value of "hello123"
has been given to you. Your task is to check and print whether the comment
variable is a number or not as well as whether it is Finite or not.
Дякуємо за ваш відгук!