Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,194,770 members, 7,955,939 topics. Date: Sunday, 22 September 2024 at 07:10 PM |
Nairaland Forum / Science/Technology / Programming / Can Someone Explain This Line Of Code To Me (1630 Views)
What Is Wrong With This Line Of Code? / I Need Help With This Line Of Code (wordpress Theme Php 7 Issue) / Someone Explain This Javascript Snippet (2) (3) (4)
Can Someone Explain This Line Of Code To Me by BabyApple(m): 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. 3 Likes |
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. 1 Like |
Re: Can Someone Explain This Line Of Code To Me by ogunjobiolaide: 3:37am On Sep 11, 2018 |
fnep2smooth:You are on point 1 Like 1 Share |
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(m): 7:11am On Sep 11, 2018 |
codemarshal08:what is the value of arr? 1 Like |
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) 1 Like |
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 1 Like |
(1) (Reply)
Want To Automate Your Sme Data Sharing Contact Me / Dreamweaver Vs Visual Studio / Python Couldn't Install On My Laptop
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 13 |