This is a quick reminder on how to use mathematical functions inside JavaScript.
Instructions
- Use
*
to indicate multiplication: Type4*x
for 4x; - Use
^
to indicate powers: Type4*x^3
for 4×3 and12*x^-6
for 12x?6. - Use parentheses to delimit the argument of a function; i.e., type
sin(x)
rather thansin x
. - Use parentheses to define the scope of an operation: For example, type
4*x*(x^2+1)^3
for 4x(x2+1)3 or4^(2*x+1)
for 42x+1 or(sin(x))^2
for (sin(x))2. - Do not type sin^2(x) for sin2(x), type
(sin(x))^2
instead. - Do not use brackets [ ] or braces { }, use only parentheses to delimit a mathematics expression.
- Functions you may use:
Trig: sin
, cos
, tan
, cot
, sec
, csc
;
Inverse Trig: asin
, acos
, atan
;
Log/exponential: ln (natural log), or use log
; exp, the natural exponential; Note: You can also enter the natural exponential exp(x) as e^x
for ex.
Misc: sqrt
, usage sqrt(x)
for ?x (or, use exponential notation: x^(1/2)
).

Technical SEO Specialist, JavaScript Programmer and Senior Full Stack Developer. On a quest to experiment with Canvas, WebGL, JavaScript, SEO and WordPress, among many other things. Founder of WPDublin and SpeedFactor, co-organizer of Dublin WordPress Meetup group.
If you like this article, go ahead and follow me on Twitter or buy me a coffee to support my work!