Can Someone Explain This Line Of Code To Me - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Can Someone Explain This Line Of Code To Me (1880 Views)
| Can Someone Explain This Line Of Code To Me by BabyApple(op): 6:08pm On Sep 10, 2018 |
<!DOCTYPE html> <html> <body> <h2>JavaScript Array Sort</h2> <p>The highest number is <span id="demo"></span>.</p> <script> var points = [40, 100, 1, 5, 25, 10]; document.getElementById("demo" .innerHTML = myArrayMax(points);function myArrayMax(arr) { return Math.max.apply(null, arr); } </script> </body> </html> My question is where does (null, arr); comes from |
| Re: Can Someone Explain This Line Of Code To Me by codemarshal08(m): 7:03pm On Sep 10, 2018 |
BabyApple:null is built in Javascript . it is used to represent "nothing" Javascript apply function accepts two (2) parameters. The first parameter is optional . passing null to it means no value. The arr is used as a parameter in the myArrayMax function definition. parameters are used to pass data to a function. In your code, the arr is used to pass the values in your point arrays to the myArrayMax function parameters are defined by programmers. |
| Re: Can Someone Explain This Line Of Code To Me by fnep2smooth(m): 12:14am On Sep 11, 2018 |
BabyApple:You are simply telling the program to sort your number you listed in your array by showing the highest number. |
| Re: Can Someone Explain This Line Of Code To Me by ogunjobiolaide: 3:37am On Sep 11, 2018 |
fnep2smooth:You are on point |
| Re: Can Someone Explain This Line Of Code To Me by fnep2smooth(m): 6:17am On Sep 11, 2018 |
ogunjobiolaide:its our work o |
| Re: Can Someone Explain This Line Of Code To Me by BabyApple(op): 7:11am On Sep 11, 2018 |
codemarshal08:what is the value of arr? |
| Re: Can Someone Explain This Line Of Code To Me by codemarshal08(m): 8:44am On Sep 11, 2018 |
BabyApple: 40, 100, 1, 5, 25, 10 View Math.max.apply(null, arr);as Math.max.apply(40, 100, 1, 5, 25, 10) |
| Re: Can Someone Explain This Line Of Code To Me by kaypompee: 3:21pm On Sep 11, 2018 |
The JS function returns the largest array value into a html span tag specified by the ID |
I Built This Beautiful AI Predictions Webapp With No Single Line Of Code • What Is Wrong With This Line Of Code? • I Need Help With This Line Of Code (wordpress Theme Php 7 Issue) • 2 • 3 • 4
Decagon Fellows #decadev Share Your Experience • Is Coding Really Hard To Learn? Advice For Beginners • I Am Willing To Pay Handsomely For This.
.innerHTML = myArrayMax(points);