₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,330,142 members, 8,444,047 topics. Date: Monday, 13 July 2026 at 12:46 AM

Toggle theme

Can Someone Explain This Line Of Code To Me - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingCan Someone Explain This Line Of Code To Me (1883 Views)

1 Reply (Go Down)

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"wink.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:
<!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"wink.innerHTML = myArrayMax(points);

function myArrayMax(arr) {
return Math.max.apply(null, arr);
}
</script>

</body>
</html>


My question is where does (null, arr); comes from
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:
<!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"wink.innerHTML = myArrayMax(points);

function myArrayMax(arr) {
return Math.max.apply(null, arr);
}
</script>

</body>
</html>


My question is where does (null, arr); comes from
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 simply telling the program to sort your number you listed in your array by showing the highest number.
You are on point
Re: Can Someone Explain This Line Of Code To Me by fnep2smooth(m): 6:17am On Sep 11, 2018
ogunjobiolaide:
You are on point
its our work o
Re: Can Someone Explain This Line Of Code To Me by BabyApple(op): 7:11am On Sep 11, 2018
codemarshal08:
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.
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:
what is the value of arr?
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
1 Reply

I Built This Beautiful AI Predictions Webapp With No Single Line Of CodeWhat Is Wrong With This Line Of Code?I Need Help With This Line Of Code (wordpress Theme Php 7 Issue)234

Algorithm Study Plan5 Free Java Ebooks For Beginners On Clintonnzedimma's RequestHow To Activate God Mode On Windows 7,8 And 10