i
Introduction Of JavaScript
Setup For JavaScript
Client-side and Server-side JavaScript
JavaScript Equivalents
JavaScript Syntax
JavaScript Variables
JavaScript Expressions
JavaScript Comments
JavaScript Identifiers
JavaScript Case Sensitive
JavaScript Function Definition
JavaScript Function Expressions
JavaScript Parameters and Arguments
JavaScript Function Invocation
JavaScript Self-invoking Functions
JavaScript Objects Definitions
JavaScript Object Properties
JavaScript Object Methods
JavaScript Object Constructors
JavaScript Object Prototypes
JavaScript Object ES5 standard
Strings Definition
Backslash escape character
Strings as Objects
String Methods
indexOf() and lastIndexOf():
search()
slice()
substring()
substr()
replace()
toUpperCase()
toLowerCase()
concat()
trim()
charAt()
charCodeAt()
split()
endsWith()
fromCharCode()
includes()
repeat()
startsWith()
valueOf()
Creating an Array
Array elements
Array Properties and Methods
Changing Elements of an array
Compare function of Array
Addition vs. Concatenation
Properties and Methods
JavaScript this Function
JavaScript let Function
Reserved Words
Removed reserved words
JavaScript Properties, Methods, and Objects
Java Properties and Objects
HTML and Window Properties, Objects and Event Handlers
Comparison operators
Logical Operator
Comparing different data types
Conditional Statements
else statement
switch statement
default statement
JavaScript Loops
JavaScript break statement
Math.random():
Math.random() is used to get a random number between 0 and 1. It always returns a number less than 1.
Example:
var randomNumber = Math.random();
The value of randomNumber varies between 0 and 1. It will always be less than 1.
Random Integers:
To generate random integers, Math.random() can be used with Math.floor().
Code:
If you need a random integer from 0 to n,
Math.floor(Math.random() * n+1);
If you need a random integer from 1 to n,
Math.floor(Math.random() * n) + 1;
Example:
var randomNumber = Math.floor(Math.random() * 16);
In the above example, the value of randomNumber will be any integer from 0 to 15.
var randomNumber = Math.floor(Math.random() * 100) + 1;
In the above example, the value of randomNumber will be any integer from 1 to 100.
Don't miss out!