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. Cancel asynchronous operations easily since execution can be paused anytime.Here’s the syntax; do not forget to add an asterisk after the “function” keyword. You can add an asterisk using any of the following −function *myFunction() {} // or function* myFunction() {} // or function*myFunction() {}ExampleLet’s see how to use a generator functionLive Demo function* display() { ... Read More
The default parameter came to handle function parameters with ease. Default parameters allow you to initialize formal parameters with default values. This is possible only if no value or undefined is passed. With ES6, you can easily set default parameters. Let’s see an exampleExampleLive Demo // default is set to 1 function inc(val1, inc = 1) { return val1 + inc; } document.write(inc(10, 10)); document.write(""); ... Read More
To implement basic Animation in JavaScript, use the DOM object properties and JavaScript. The following list contains different DOM methods.We are using the JavaScript function getElementById() to get a DOM object and then assigning it to a global variable imgObj.We have defined an initialization function init() to an initialize imgObj where we have to set its position and left attributes.We are calling an initialization function at the time of window load.Finally, we are calling moveRight() function to increase the left distance by 10 pixels. You could additionally set it to a negative value to move it to the left side. ... Read More
To find whether the browser supports JavaScript or not, use the tag. The HTML tag is used to handle the browsers, which do recognize tag but do not support scripting. This tag is used to display an alternate text message.ExampleLive Demo HTML noscript Tag Your browser does not support JavaScript!
Fat arrow function solves the issue of lexical binding “this”. It gets the context of “this “and you can fulfill the same purpose since fast arrow does not have its own this. Fat arrow function as the name suggests helps in decreasing line of code. The syntax => shows fat arrow.Example$('.button1').click(function () { setTimeout(function () { $(this).text('demo'); } ,400); });The above gives an error since the function() defines this as a global object. Let’s see how to solve it using fat arrow function and the context of “this” −$('.button1').click(function () { setTimeout( () => ... Read More
To remove a property from a JavaScript object, use the delete keyword. You can try to run the following code to learn how to remove a propertyExampleLive Demo var cricketer = { name:"Amit", rank:1, points: 150 }; delete cricketer.rank; document.getElementById("demo").innerHTML = cricketer.name + " has " + cricketer.rank + " rank.";
Methods which uses variable arguments (varargs, arguments with three dots) are known as variadic functions.ExampleLive Demopublic class Sample { void demoMethod(String... args) { for (String arg: args) { System.out.println(arg); } } public static void main(String args[] ){ new Sample().demoMethod("ram", "rahim", "robert"); new Sample().demoMethod("krishna", "kasyap"); } }Outputram rahim robert krishna kasyap
The immediate function executes as soon as it is defined. To understand the role of immediate function, let’s see the difference between a function and an immediate function −Here’s immediate function −(function() { var str = "display"; }()); function display() { // this returns undefined alert(str); }Here’s a function −var str = "display"; function display() { // This returns "display" alert(str); }Let’s see another example of immediate functions −var name = 'Amit'; (function(sName) { alert( 'Student name = ' + sName ); }(sName))
The hidden.bs.modal event in Bootstrap fires when the modal is completely hidden.Firstly, click on the hide button to hide the modal −$("#button1").click(function(){ $("#newModal").modal("hide"); }); After clicking the button, the hidden.bs.modal fires and generates an alert using the following script −$("#newModal").on('hidden.bs.modal', function () { alert('The modal is completely hidden now!'); });Let us see an example to implement the hidden.bs.modal event −ExampleLive Demo Bootstrap Example #button1 { width: 140px; padding: 20px; bottom: 150px; z-index: 9999; ... Read More
If you want to add rounded corners to an element, then use the rounded-bottom class.Use it on any element like −Above, we have set demo as well for class, for our div that is a rectangle.Here is our demo CSS class − .demo { width: 110px; height: 150px; background-color: blue; } You can try to run the following code to add bottom rounded corners to an element −ExampleLive Demo Bootstrap Example .demo { width: 110px; height: 150px; background-color: blue; } Rectangle We have a rectangles with rounded corners (bottom):
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP