Functions and methods are the same in JavaScript, but a method is a function, which is a property of an object.The following is an example of a function in JavaScript −function functionname(param1, param2){ // code }ExampleThe method is a function associated with an object. The following is an example of a method in JavaScript − Live Demo var employee = { empname: "David", department : "Finance", id : 002, details : function() { return this.empname + " with Department " + this.department; } }; document.write(employee.details()); Output
Default ParametersThe default parameter came to handle function parameters with ease. You can easily set Default parameters to allow initializing formal parameters with default values. This is possible only if no value or undefined is passed. Example Live Demo // default is set to 1 function inc(val1, inc = 1) { return val1 + inc; } document.write(inc(10, 10)); document.write(""); document.write(inc(10)); ... Read More
To remove spaces in JavaScript, you can try to run the following regular expression. It removes the spaces from a string −Example Live Demo var str = "Welcome to Tutorialspoint"; document.write(str); //Removing Spaces document.write(""+str.replace(/\s/g, '')); Output
To find multiple matches, write a JavaScript regular expression. You can try to run the following code to implement regular expression for multiple matches −Example var url = 'https://www.example.com/new.html?ui=7&demo=one&demo=two&demo=three four', a = document.createElement('a'); a.href = url; var demoRegex = /(?:^|[&;])demo=([^&;]+)/g, matches, demo = []; while (matches = demoRegex.exec(a.search)) { demo.push(decodeURIComponent(matches[1])); } document.write(demo);
To remove all special characters from a JavaScript string, you can try to run the following code −Example var str = "@!Welcome to our website$$"; document.write(str); // Removing Special Characters document.write(""+str.replace(/[^\w\s]/gi, ''));
To get a JavaScript stack trace, simply add the following in your code. It will display the stack trace −Example Live Demo function stackTrace() { var err = new Error(); return err.stack; } console.log(stackTrace()); document.write(stackTrace()); Stacktrace prints above. Output
You cannot skip a character in a capture group. A match is always consecutive, even when it contains things like zero-width assertions.ExampleHowever, you can access the matched groups in a regular expression like the following code − var str = "Username akdg_amit"; var myReg = /(?:^|\s)akdg_(.*?)(?:\s|$)/g; var res = myReg.exec(str); document.write(res[1]);
You cannot do this with JavaScript since it takes the system time which displays the current date with Date object. However, you can change the current date by changing the timezone as in the following code −Example Live Demo var date, offset, nd; date = new Date(); document.write("Current: "+date); utc = date.getTime() + (date.getTimezoneOffset() * 60000); // Singapore is GMT+8 offset = 8; nd = new Date(utc + (3600000*offset)); document.write("Singapore Time: "+nd.toLocaleString()); Output
Firstly, set two lists.List val1 = new List { 25, 30, 40, 60, 80, 95, 110 }; List val2 = new List { 27, 35, 40, 75, 95, 100, 110 };Now, use the Intersect() method to get the intersection between two lists.IEnumerable res = val1.AsQueryable().Intersect(val2);Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Demo { static void Main() { List val1 = new List { 25, 30, 40, 60, 80, 95, 110 }; List val2 = new List { 27, 35, 40, 75, 95, 100, 110 }; IEnumerable res = val1.AsQueryable().Intersect(val2); Console.WriteLine("Intersection of both the lists..."); foreach (int a in res) { Console.WriteLine(a); } } }OutputIntersection of both the lists... 40 95 110
The shell is the command interpreter on the Linux systems. It the program that interacts with the users in the terminal emulation window. Shell commands are instructions that instruct the system to do some action.Some of the commonly used shell commands are −basenameThis command strips the directory and suffix from filenames. It prints the name of the file with all the leading directory components removed. It also removes a trailing suffix if it is specified.Example of basename is as follows −$ basename country/city.txtThis gets the name of the file i.e. city which is present in folder country.city.txtcatThis command concatenates and ... Read More
 
 Data Structure
 Data Structure Networking
 Networking RDBMS
 RDBMS Operating System
 Operating System Java
 Java MS Excel
 MS Excel iOS
 iOS HTML
 HTML CSS
 CSS Android
 Android Python
 Python C Programming
 C Programming C++
 C++ C#
 C# MongoDB
 MongoDB MySQL
 MySQL Javascript
 Javascript PHP
 PHP 
		 
		 
		 
		 
		 
		 
		 
		 
		