1/* Spread syntax ( ex. ...arrayName) allows an iterable such as an array expression or string
2to be expanded in places where zero or more arguments (for function calls)
3elements (for array literals) are expected, or an object expression to be
4expanded in places where zero or more key-value pairs (for object literals)
5are expected. */
6
7
8//example
9function sum(x, y, z) {
10 return x + y + z;
11}
1// Function: creates a new paragraph and appends it to the bottom of the HTML body.
2
3function createParagraph() {
4 let para = document.createElement('p');
5 para.textContent = 'You clicked the button!';
6 document.body.appendChild(para);
7}
8
9/*
10 1. Get references to all the buttons on the page in an array format.
11 2. Loop through all the buttons and add a click event listener to each one.
12
13 When any button is pressed, the createParagraph() function will be run.
14*/
15
16const buttons = document.querySelectorAll('button');
17
18for (let i = 0; i < buttons.length ; i++) {
19 buttons[i].addEventListener('click', createParagraph);
20}
1JS is th short form of Javascript.
2It is used to make a website functionable.It is the heart of a website!
3 Javascript contains many functions like:
4◻ document.getElementById(id).innerHTML = a new html text