How it works
- A simple recursive function:
- An anonymous function (or lambda):
- Variadic function demonstration
- Immediately-invoked function expressions are often used to create modules, as before ECMAScript 2015 there was no built-in construct in the language. Modules allow gathering properties and methods in a namespace and making some of them private
- Firstly, go to your test site and create a new folder named ‘scripts’ (without the quotes). Then, within the new scripts folder, create a new file called main.js and save it into the scripts folder.
- Next, in your index.html file, enter the following syntax on a new line before the closing </body> tag:
- Now, add this code to the main.js file:
var myHeading = document.querySelector(‘h1’);
myHeading.textContent = ‘Hello world!’;
Explanation: You did this by first grabbing a reference to your heading, and store it in a variable called myHeading, using a querySelector function. The first thing you need to do with an element is to select it. The code you wrote after that is to set the value of the myHeading variable’s textContent, which represents the content of the heading, to “Hello world!”.
So if you happen to need support from professional and experienced software development company with your upcoming project, or you’ve just passed through your coding journey and now looking for opportunities to join the coolest software programmer squad ever, Designveloper is right here waiting for you!