JavaScript Booleans
A JavaScript Boolean represents one of two values: true or false. Boolean Values Very often, in programming, you will need a data type that can only have one of two values, like YES / NO ON / OFF TRUE /…
A JavaScript Boolean represents one of two values: true or false. Boolean Values Very often, in programming, you will need a data type that can only have one of two values, like YES / NO ON / OFF TRUE /…
Math.random() Math.random() returns a random number between 0 (inclusive), and 1 (exclusive): Example // Returns a random number: Math.random(); Math.random() always returns a number lower than 1. JavaScript Random Integers Math.random() used with Math.floor() can be used to return random…
The JavaScript Math object allows you to perform mathematical tasks on numbers. Example Math.PI; The Math Object Unlike other objects, the Math object has no constructor. The Math object is static. All methods and properties can be used without creating…
Set Date methods let you set date values (years, months, days, hours, minutes, seconds, milliseconds) for a Date Object. Set Date Methods Set Date methods are used for setting a part of a date: Method Description setDate() Set the day…
The new Date() Constructor In JavaScript, date objects are created with new Date(). new Date() returns a date object with the current date and time. Get the Current Time const date = new Date(); Date Get Methods Method Description getFullYear()…
JavaScript Date Input There are generally 3 types of JavaScript date input formats: Type Example ISO Date “2015-03-25” (The International Standard) Short Date “03/25/2015” Long Date “Mar 25 2015” or “25 Mar 2015” The ISO format follows a strict standard…
JavaScript Date Objects let us work with dates: Mon Feb 24 2025 06:31:40 GMT+0330 (Iran Standard Time) Examples const d = new Date(); const d = new Date(“2022-03-25″); Note Date objects are static. The “clock” is not “running”. The…
ECMAScript 2015 (ES6) In 2015, JavaScript introduced an important new keyword: const. It has become a common practice to declare arrays using const: Example const cars = [“Saab”, “Volvo”, “BMW”]; Cannot be Reassigned An array declared with const cannot be…
JavaScript Array forEach() The forEach() method calls a function (a callback function) once for each array element. Example const numbers = [45, 4, 9, 16, 25]; let txt = “”; numbers.forEach(myFunction); function myFunction(value, index, array) { txt += value…