Double equals (==) is abstract equality comparison operator, which transforms the operands to the same type before making the comparison. For example,5 == 5 //true '5' == 5 //true 5 == '5' //true 0 == false //trueTriple equals (===) are strict equality comparison operator, which returns false for different types and different content.For example,5 === 5 // true 5 === '5' // false var v1 = {'value':'key'}; var v2 = {'value': 'key'}; v1 === v2 //false
The conditional operator or ternary operator first evaluates an expression for a true or false value and then executes one of the two given statements depending upon the result of the evaluation.S.NoOperator & Description1? : (Conditional )If Condition is true? Then value X: Otherwise value YExampleYou can try to run the following code to understand how Ternary Operator works in JavaScriptLive Demo var a = 10; var b = 20; var linebreak = ""; document.write ("((a > b) ? 100 : 200) => "); result = (a > b) ? 100 : 200; document.write(result); document.write(linebreak); document.write ("((a < b) ? 100 : 200) => "); result = (a < b) ? 100 : 200; document.write(result); document.write(linebreak);
To determine if an argument is sent to function, use “default” parameters.ExampleYou can try to run the following to implement itLive Demo function display(arg1 = 'Tutorials', arg2 = 'Learning') { document.write(arg1 + ' ' +arg2+""); } display('Tutorials', 'Learning'); display('Tutorials'); display();
A finger search on a data structure is defined as an extension of any search operation that structure supports, where a reference (finger) to an element in the data structure is given along with the query. While the search time for an element is most frequently denoted as a function of the number of elements in a data structure, finger search times are treated as a function of the distance between the element and the finger.In a set of m elements, the distance d(a, b) between two elements a and b is their difference in rank. If elements a and ... Read More
To use a variable number of arguments to function, use the arguments object.ExampleYou can try to run the following code to implement arguments to a function in JavaScriptLive Demo function functionArgument(val1, val2, val3) { var res = ""; res += "Expected Arguments: " + functionArgument.length; res += ""; res += "Current Arguments : " + arguments.length; res += ""; res += "Each argument = " for (p = 0; p < arguments.length; p++) { res += ""; res += functionArgument.arguments[p]; res += " "; } document.write(res); } functionArgument(20, 50, 80, "Demo Text!","Hello World", new Date())
The JavaScript version of sleep() is “await”. The await feature pauses the current aync function.ExampleYou can try to run the following code to implement sleep in JavaScriptLive Demo function setSleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } async function Display() { document.write('Wait for 5 seconds!'); await setSleep(5000); document.write('After 5 seconds!'); } Display();
The “return” statement in JavaScript mentions a value, which you like to return. Inside a function, the value is returned to the function caller.ExampleYou can try to run the following code to implement return statement inside a functionLive Demo function multiply(num1, num2) { return num1 * num2; } var result = multiply(5, 10); document.write("Multiplication: "+result);
A method in JavaScript is the action performed on objects. A JavaScript method has a function definition, which is stored as a property value. ExampleLet’s see an example to define a method in JavaScriptLive Demo var department = { deptName: "Marketing", deptID : 101, deptZone : "North", details : function() { return "Department Details" + "Name: " + this.deptName + " Zone: " + this.deptZone + "ID: " + this.deptID; } }; document.getElementById("myDept").innerHTML = department.details();
To achieve what you want, use JavaScript Closures. A closure is a function, which uses the scope in which it was declared when invoked. It is not the scope in which it was invoked.ExampleLet’s take your example and this is how you can achieve your task. Here, innerDisplay() is a JavaScript closure.Var myFunction = (function () { function display() { // 5 }; function innerDisplay (a) { if (/* some condition */ ) { // 1 // 2 display(); }else { // 3 // 4 display(); } } return innerDisplay; })();
Fat arrow function as the name suggests helps in decreasing line of code. The syntax => shows fat arrow. This also avoids you to write the keyword “function” repeatedly. Arrow functions are generally used for a non-method function. Let’s see how to use arrow functions used as methods:ExampleYou can try to run the following code to implement arrow functions used as methodsLive Demo 'use strict'; var ob1 = { val1: 75, val2: 100, x: () => document.write(this.val1, this), y: function() { document.write(""+this.val1, this); }, z: function() { document.write(""+this.val2, this); }, } ob1.x(); ob1.y(); ob1.z();
 Data Structure
 Networking
 RDBMS
 Operating System
 Java
 iOS
 HTML
 CSS
 Android
 Python
 C Programming
 C++
 C#
 MongoDB
 MySQL
 Javascript
 PHP