js fill array with count elements
Array(3).fill(4); // [4, 4, 4]
Here is what the above code is Doing:
1. We create an array with 3 elements.
2. We fill the array with the value 4.
3. We return the array.
Array(3).fill(4); // [4, 4, 4]
Here is what the above code is Doing:
1. We create an array with 3 elements.
2. We fill the array with the value 4.
3. We return the array.
function addNumber (num1, num2){ consle.log(arggrement[3]); const result = num1 + num2; return result; } const sum = addNumber(23,13 50, ); console.log(sum) Here is what the above code is Doing: 1. We are creating a function called addNumber. 2. We are passing two parameters, num1 and num2. 3. We are creating a variable called result and…
function myApp() { const [data, setdata] = useState() useEffect(() => { async function fetchMyAPI() { const response = await fetch(‘api/data’) response = await response.json() setdata(response) } fetchMyAPI() }, []) } Here is what the above code is Doing: 1. We’re using the useState hook to create a state variable called data and a function called…
$(document).ready(function() { $(‘#submit’).click(function() { var list = [‘Car’, ‘Bike’, ‘Scooter’]; for (var value of list) { $(‘#container’) .append(“) .append(`${value}`) .append(“); } }) }); Here is what the above code is Doing: 1. When the user clicks the button, the click event handler is called. 2. The click event handler calls the for…of loop. 3. The…
Vue.component(‘wrapper’, { name: ‘Wrapper’, template: “, mounted () { console.log(this.$slots); } }); Here is what the above code is Doing: 1. We’re creating a component called wrapper. 2. We’re giving it a name of Wrapper. 3. We’re giving it a template of a div with a slot. 4. We’re logging the $slots property to the…
new Array(len).fill(0); Here is what the above code is Doing: 1. We are creating a new array of length len. 2. We are filling the array with 0s.
import { useCallback } from ‘react’ Here is what the above code is Doing: 1. We’re importing the useState and useCallback hooks from React. 2. We’re creating a function called useInputs. 3. We’re creating a state variable called inputs and a function called setInputs. 4. We’re creating a function called onChange. 5. We’re returning an…