Front End Technology Articles

Page 17 of 652

How to Scroll to the top of the page using JavaScript/ jQuery?

Anjana
Anjana
Updated on 11-Mar-2026 309 Views

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 More

How to use variable number of arguments to function in JavaScript?

Krantik Chavan
Krantik Chavan
Updated on 11-Mar-2026 697 Views

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 More

What is &quot;function*&quot; in JavaScript?

Smita Kapse
Smita Kapse
Updated on 11-Mar-2026 338 Views

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 More

What is the use of JavaScript eval function?

Vrundesha Joshi
Vrundesha Joshi
Updated on 11-Mar-2026 400 Views

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 More

Which one is better to use for a JavaScript link, &ldquo;#&rdquo; or &ldquo;javascript:void(0)&rdquo;?

Smita Kapse
Smita Kapse
Updated on 11-Mar-2026 237 Views

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 More

How to determine if an argument is sent to the JavaScript function?

Krantik Chavan
Krantik Chavan
Updated on 11-Mar-2026 151 Views

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 More

How can I pass a parameter to a setTimeout() callback?

Daniol Thomas
Daniol Thomas
Updated on 11-Mar-2026 2K+ Views

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 More

How to add a number of months to a date using JavaScript?

Paul Richard
Paul Richard
Updated on 11-Mar-2026 810 Views

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 More

How to call a parent window function from an iframe using JavaScript?

Paul Richard
Paul Richard
Updated on 11-Mar-2026 4K+ Views

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 More

Is it required to have a return a value from a JavaScript function?

George John
George John
Updated on 11-Mar-2026 2K+ Views

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
Showing 161–170 of 6,518 articles
« Prev 1 15 16 17 18 19 652 Next »
Advertisements