Esteem and Reference Types 

Factors come in two unique sorts: esteem types and reference types. Boolean qualities and numbers are esteem based sorts, while strings, questions, exhibits, and capacities are reference types. How about we take a gander at the distinctions. 

Esteem types involve a settled size in memory. A Boolean incentive for instance just takes one piece. All numbers in JavaScript are 64-bit skimming point numbers, so each number is spoken to by 8 bytes. A reference type variable holds a reference to the esteem whose length isn't settled and can be of any size 

Another contrast among esteem and reference types is that esteem types are replicated, passed, and analyzed by esteem. Reference types, are replicated, passed, and analyzed by reference, as opposed to by esteem. How about we see esteem types first: 

var x = 1; 

var y = x; 

alert(x == y);/=> genuine 

alert(x === y);/=> genuine 

x = 6; 

alert(x);/=> 6 

alert(y);/=> 1 

alert(x == y);/=> false 

alert(x === y);/=> false 

At the point when variable y is appointed to x it duplicates its esteem and following the task any connection among x and y is disjoined. Along these lines, changing the estimation of x has no effect on the estimation of y. 

How to Build a Simple Chrome Extension in JavaScript

Consider this precedent where a reference type is duplicated: 

var x = { make: "Toyota" }; 

var y = x; 

alert(x == y);/=> genuine 

alert(x === y);/=> genuine 

x.make = "Passage"; 

alert(x.make);/=> Ford 

alert(y.make);/=> Ford 

alert(x == y);/=> genuine 

alert(x === y);/=> genuine 

Following the execution of the second explanation in which x is appointed to y, y alludes to a similar protest that x alludes to. JavaScript does not make another duplicate of that protest. In the event that you roll out any improvements to the fundamental question through x, you can see these progressions through y and the other way around. 

String, Boolean, and Number 

String type 

A string speaks to an arranged grouping of at least zero 16-bit esteems. Each esteem normally speaks to a Unicode character. Unicode is intended to speak to the majority of the characters found in every single human dialect. 

A string is enveloped by either twofold or single statements. Including a solitary statement character inside a string that is delimited by twofold statements is no issue; the equivalent is valid for including a twofold statement character in a solitary statement delimited string. Including a solitary statement in the last requires a departure character before the single statement, as so \'. Other basic getaway characters incorporate \n = newline; \r = carriage return; \t = tab, and \\ = oblique punctuation line. 

Three dots ( … ) in JavaScript

A string exacting can be part crosswise over at least one lines by putting a getaway character \ (called a continuation character) toward the finish of each line aside from the last one. The \ character does not turn into a piece of the string strict. Here are a few instances of string literals: 

var s1 = "Don't disregard Peter's input"; 

var s2 = 'Don\'t disregard Peter\'s input'; 

var s3 = 'Andrew Fuller\n Bob Springsteen'; 

var s4 = "Andrew Fuller, \ 

Bounce Springsteen, \ 

Helena Williams"; 

alert(s1); 

alert(s2); 

alert(s3); 

alert(s4); 

Note that utilizing the continuation character is commonly not suggested. 

Here are some other string individuals you every now and again utilize: length, and charAt. 

var s = "Paris, London, Amsterdam"; 

alert(s.length);/=> 24 

alert(s.charAt(0));/=> P. First character 

alert(s.charAt(s.length-1));/=> m. Last character 

Furthermore, here are some extra often utilized string strategies: indexOf, lastIndexOf, toLowerCase, substring, supplant, and split. 

var s = "Paris, London, Amsterdam"; 

/Gets position of initial 'a', profits 1 

alert(s.indexOf("a")); 

/Gets position of initial 'a' beginning at 3, returns 22 

alert(s.indexOf("a", 3)); 

/Gets position of keep going 'o', returns 11 

alert(s.lastIndexOf("o")); 

/Converts string to bring down case 

alert(s.toLowerCase()); 

/Gets substring beginning from the fifteenth character to the last, 

alert(s.substring(14, s.length)); 

/Replaces "London" with "Berlin" 

alert(s.replace("London", "Berlin")); 

/parts into a variety of substrings utilizing ", " separator 

alert("Array: " + s.split(", ")); 

When looking at two strings they are viewed as equivalent when they have a similar length and a similar grouping of characters in relating positions. 

var str1 = "Hi World"; 

var str2 = "Hi" + " World"; 

alert(str1 == str2);/=> genuine 

alert(str1 === str2);/=> genuine 

JavaScript strings are permanent 

When we say that strings are changeless it implies that once made, the substance of a string is of settled length and can't be adjusted. String may seem impermanent when you work with them yet they are not.: they are changeless inside. JavaScript does not offer any technique or property that gives you a chance to modify the substance of a string esteem. 

How to Create A Countdown Timer with Progress Bar in JavaScript

Once more, adjusting the string may seem to work, yet truth be told, another string is produced. In the accompanying precedent, b is referencing indistinguishable string from a. Be that as it may, while adjusting the hidden string through the b reference, another string is made inside and its reference is doled out to b without influencing the first string referenced by a. 

var a = "Hello"; 

var b = a; 

b += ", what's up"; 

alert(b);/=> Hey, what's up 

alert(a);/=> Hey 

String techniques like supplant and toLowerCase seem to adjust the string on which they work, yet they likewise return new strings. 

Boolean sort 

The Boolean sort has two strict qualities: genuine and false. Note that genuine and false are dialect catchphrases and are not equivalent to 1 and 0. 

A wide range of qualities in JavaScript have Boolean reciprocals. An unfilled string, invalid, vague, NaN, 0, - 0, and false itself assess to the Boolean esteem false. Every one of these sorts and their qualities are alluded to as falsy. Then again, a non-void string, any non-zero number including Infinity, any question, and genuine itself assess to the Boolean esteem genuine. These sorts and their qualities are alluded to as truthy. Despite the fact that truthy and falsy are informal terms, they are broadly utilized in the JavaScript people group. 

JavaScript has an uncommon Boolean throwing capacity that is utilized to change over an incentive into its Boolean proportionate – basically deciding if the go in articulation is truthy or falsy. 

var void = ""; 

alert(Boolean(empty));/=> false 

var nonEmpty = "JavaScript is cool!"; 

alert(Boolean(nonEmpty));/=> genuine 

Programmed transformations to Boolean counterparts are normal in contingent proclamations. 

var vehicle = { make: "Toyota" }; 

var show = genuine; 

on the off chance that (vehicle && show) {/=> genuine 

alert(car.make); 

vehicle = invalid; 

on the off chance that (vehicle) {/=> false 

alert("drive my vehicle"); 

The first if proclamation returns genuine and along these lines the alarm shows. The second if-proclamation returns false and does not get executed. 

String, Boolean, and Number properties are perused as it were 

Factors of sort string, number, and Boolean have properties and strategies, however they are not objects. When you read a property or strategy from these sorts, JavaScript makes an impermanent question, called a wrapper protest, by calling the String(), Number(), or Boolean() constructor in the background. Note that you can likewise unequivocally call these constructor capacities and make wrapper objects. 

var message = "Hi World"; 

message.howlong = message.length;/=> sets property on protest 

alert(message. howlong);/=> vague 

At the point when the second articulation is executed, JavaScript makes an impermanent String wrapper protest. At that point it includes a client characterized property called howlong on it, sets its esteem, and in this manner disposes of that question. This demonstrates String objects are false questions since they don't acknowledge new properties. 

In rundown, you can't set properties to numbers, strings, or Booleans; any adjustment on the wrapper objects isn't perpetual. 

Number-String changes 

JavaScript offers three different ways to expressly change over a string to a number. They are the Number constructor capacity, parseFloat, and parseInt. The last two capacities have some unique conduct. Here is a precedent utilizing the Number constructor work which takes a string contention: 

var num = Number("1.73"); 

alert(num);/=> 1.73 

The parseFloat work changes over strings to coasting point numbers. It disregards any non-numeric qualities that show up after numeric characters: 

alert(parseFloat("1.73"));/=> 1.73 

alert(parseFloat("USD 1.73"));/=> NaN 

alert(parseFloat("1.73 USD"));/=> 1.73 

The parseInt work changes over string to number qualities. It likewise overlooks any trailing non-numeric qualities: 

alert(parseInt("1.73"));/=> 1, adjusted down 

alert(parseInt("USD 1.73"));/=> NaN 

alert(parseInt("1.73 USD"));/=> 1 

alert(parseInt("0x10"));/=> 16. translated as hex 

How to Play Audio After Few Seconds or Delay in JavaScript

Here are some extra transformation techniques: parseInt additionally gives you a chance to indicate the base of the number. On the off chance that you need JavaScript to regard your numeric string as base 10 number, pass 10 as the second parameter to parseInt(). Pass 8 if the string is an octal number. 

alert(parseInt("1.73", 10));/=> 1 

alert(parseInt("10", 16));/=> 16 

alert(parseInt("111", 2));/=> 7 

alert(parseInt("16", 8));/=> 14 

When revealing money related qualities, you are probably going to perform number-to-string changes. In the yield string, you may get a kick out of the chance to institutionalize the quantity of decimal places by adjusting the trailing digits or cushioning with zeros. The Number protest offers techniques that you can use to change over numbers to strings. For instance, the toFixed strategy changes over it to a string while at the same time keeping various decimals.

var num = 7.679; 

alert(num.toFixed(0));/=> "8" adjusted to closest entire number 

alert(num.toFixed(2));/=> "7.68" 

alert(num.toFixed(4));/=> "7.6790" 

Here are two extra change techniques: toPrecision and toExponential. 

var num = 17305.73; 

alert(num.toPrecision(3));/=> "1.73e+4" 

alert(num.toPrecision(5));/=> "17306" 

alert(num.toPrecision(6));/=> "17305.7" 

alert(num.toPrecision(8));/=> "17305.730" 

alert(num.toExponential(1));/=> "1.7e+4" 

alert(num.toExponential(3));/=> "1.731e+4" 

JavaScript Math Object 

For numerical calculations you utilize the Math question. There is no compelling reason to make a case of Math to get to its properties and techniques since it is a static question. You essentially utilize the Math protest specifically and call its technique or property names. The following are max, min and abs techniques: 

alert(Math.max(1, 2));/=> 2 

alert(Math.min(1, 2));/=> 1 

alert(Math.abs(- 2));/=> 2 

Next are some trigonometry related things: the consistent PI, and sin and cos. 

alert(Math.PI);/=> estimation of pi 

alert((180/Math.PI) * Math.sin(1));/=> 90 (degrees) 

alert((180/Math.PI) * Math.cos(0));/=> 90 (degrees) 

At last some adjusting techniques: 

alert(Math.round(Math.PI));/=> 3, round up/down to closest entire nbr 

alert(Math.floor(9.69));/=> 9, round down to closest entire number 

alert(Math.ceil(9.69));/=> 10, round up to closest entire number 

JavaScript Date Object 

To perform date and time figurings you utilize the Date question. The Date protest holds a date as the quantity of milliseconds that have gone since Jan 1 1970 12:00 AM UTC. On the off chance that you make another Date protest it will be set to the current date and time in the program. 

var current = new Date(); 

alert(current);/=> current date and time 

The time zone is controlled by the framework settings. In the model beneath, how about we accept that the time zone where this code is run is set to Paris i.e. UTC + 1:00. Contingent upon your timezone your outcomes will vary. 

/=> Jan 02 2011, 6:55:42 PM nearby time 

var date = new Date(2011, 0, 2, 18, 55, 42); 

alert(date.getDay());/=> 0. 0– Sunday, 1– Monday, etc 

alert(date.getDate());/=> 2. second day of the month 

alert(date.getMonth());/=> 0. 0– January, 1– February, etc 

alert(date.getFullYear());/=> 2011. 

alert(date.getUTCHours());/=> 17. Paris is 1:00 hour ahead from UTC 

The contrast between two dates is returned in milliseconds. 

/=> Jan 01 2011 12:00:00 AM nearby time 

var from = new Date(2011, 0, 1); 

/=> Jan 02 2011, 6:55:42 PM nearby time 

var to = new Date(2011, 0, 2, 18, 55, 42); 

var timeElapsed = to - from; 

alert(timeElapsed);/=> 154542000 milliseconds 

Here are instances of arranging date and time. If it's not too much trouble take note of that your profits will vary contingent upon your timezone: 

/=> Jan 02 2011, 6:55:42 PM nearby time 

var date = new Date(2011, 0, 2, 18, 55, 42); 

alert(date.toString());/=> Sun Jan 2 18:55:42 CST 2011 

alert(date.toDateString());/=> Sun Jan 2 2011 

alert(date.toTimeString());/=> 18:55:42 CST 

alert(date.toLocaleDateString());/=> Sunday, January 02, 2011 

alert(date.toLocaleTimeString());/=> 6:55:42 PM 

alert(date.toUTCString());/=> Mon, 3 Jan 2011 00:55:42 UTC 

Be watchful when you enter an invalid date like January 32, 2011. In the vast majority of the programs like IE, Firefox, it is quietly changed to February 1. 

alert(new Date(2011, 0, 32));/=> Feb 1, 2011

Live word counter from HTML textarea in JavaScript
A Beginner’s Guide to JavaScript
Conditional JavaScript for Experts
Functional Programming In Javascript & NodeJS, Explained With Example