Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Front End Technology Articles
Page 17 of 652
How to Scroll to the top of the page using JavaScript/ jQuery?
Example $("a").click(function() { $("html, body").animate({ scrollTop: 0 }, "slow"); return false; }); TOP OF PAGE This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo ...
Read MoreHow to use variable number of arguments to function in JavaScript?
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 JavaScript 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())
Read MoreWhat is "function*" in JavaScript?
The function* declaration is used to define a generator function. It returns a Generator object. Generator Functions allows execution of code in between when a function is exited and resumed later. So, generators can be used to manage flow control in a code.SyntaxHere’s the syntax −function *myFunction() {} // or function* myFunction() {} // or function*myFunction() {}Let’s see how to use generator functionExample function* display() { var num = 1; while (num < 5) yield num++; } var myGenerator = display(); document.write(myGenerator.next().value); document.write(""+myGenerator.next().value); document.write(""+myGenerator.next().value); document.write(""+myGenerator.next().value); document.write(""+myGenerator.next().value);
Read MoreWhat is the use of JavaScript eval function?
The JavaScript eval() is used to execute an argument. The code gets execute slower when the eval() method is used. It also has security implementations since it has a different scope of execution. In addition, use it to evaluate a string as a JavaScript expression.The eval() method is not suggested to use in JavaScript since it executes slower and improper usage opens your website to injection attacks.ExampleHere’s how you can implement eval() function var a = 30; var b = 12; var res1 = eval("a * b") + ""; var res2 = eval("5 + 10") + ""; document.write(res1); document.write(res2);
Read MoreWhich one is better to use for a JavaScript link, “#” or “javascript:void(0)”?
Using “javascript:void(0)” is definitely better, since its faster. Try to run both the examples in Google Chrome with the developer tools. The “javascript:void(0)” method takes less time than the only #.Here’s the usage of “javascript: void(0)”:If inserting an expression into a web page results in an unwanted effect, then use JavaScript void to remove it. Adding “JavaScript:void(0)”, returns the undefined primitive value.The void operator is used to evaluate the given expression. After that, it returns undefined. It obtains the undefined primitive value, using void(0).The void(0) can be used with hyperlinks to obtain the undefined primitive valueExample ...
Read MoreHow to determine if an argument is sent to the JavaScript function?
To determine if an argument is sent to function, use “default” parameters.ExampleYou can try to run the following to implement it function display(arg1 = 'Tutorials', arg2 = 'Learning') { document.write(arg1 + ' ' +arg2+""); } display('Tutorials', 'Learning'); display('Tutorials'); display();
Read MoreHow can I pass a parameter to a setTimeout() callback?
To pass a parameter to setTimeout() callback, use the following syntax −setTimeout(functionname, milliseconds, arg1, arg2, arg3...)The following are the parameters −function name − The function name for the function to be executed.milliseconds − The number of milliseconds.arg1, arg2, arg3 − These are the arguments passed to the function.ExampleYou can try to run the following code to pass a parameter to a setTimeout() callback Submit function timeFunction() { setTimeout(function(){ alert("After 5 seconds!"); }, 5000); } Click the above button and wait for 5 seconds.
Read MoreHow to add a number of months to a date using JavaScript?
To add a number of months to a date, first get the month using getMonth() method and add a number of months.ExampleYou can try to run the following code to add a number of months var d, e; d = new Date(); document.write(d); e = d.getMonth()+1; document.write("Incremented month = "+e);
Read MoreHow to call a parent window function from an iframe using JavaScript?
To call a parent window function, use “window.top”.ExampleYou can try to run the following code to call a parent window function from an iframe function display(){ alert("Hello World!"); } Click
Read MoreIs it required to have a return a value from a JavaScript function?
A JavaScript function can have an optional return statement i.e. it’s optional to return a value. This statement should be the last statement in a function.For example, you can pass two numbers in a function and then you can expect the function to return their multiplication to your calling program.ExampleTry the following example. It defines a function that takes two parameters and concatenates them before returning the resultant in the calling program. function concatenate(first, last){ var full; full = first + ...
Read More