The slope of a function that is not represented by a straight line change at any point, so it is not a constant value as for a straight line, and has no sense to speak of the slope of the function.
But, with suitable conditions, the graph of a function can have a straight line that is tangent to a point, so we can define the slope af the function at this point as the slope of the tangent.
But here there is a problem: what we means exactly for a "straight line tangent to a point"? We know that a straight line is well defined when we have two points, so, given a point $(x,f(x))$ and a point $(x+h,f(x+h))$ we can write the slope of the function that passes between these points as:
$$
\frac{f(x+h)-f(x)}{h}
$$
than we define the tangent as the line that passes through $(x,f(x))$ and has slope the limit of this quotient when $h \rightarrow 0$ if this limit exists.
So, at the same time, we define the tangent and his slope, that can be thinked as the slope of the function at the given point.