One Pager Cheat Sheet
- In this lesson, we will discuss how
variables
are used, as well as specific math operations in programming. - A variable is a
placeholder
for storing data values in a programming language which can be assigned or re-assigned using theequal sign
(=
). - Variables in JavaScript are declared by
var
,let
, orconst
, and the preferred form for a deep dive islet
andconst
, which offers improved scope overvar
. - The code snippet is invalid due to the lack of a valid
variable name
after thevar
keyword. - The value of
c
is assigned the same value asb
, which is 10. - Using aritmetic operators, one can perform basic
math operations
like addition, subtraction, multiplication, division, modulus and exponentiation in any programming language. - Math operations in JavaScript can be performed by directly specifying a mathematical statement or by assigning the result to a variable
c
, such asvar c = a + b
for more complex calculations. - JavaScript provides an abundance of mathematical operations through its
Math
object, and you can see examples of some of these with the available list at Mozilla Developer Network. - The output of the code block is
Math.sqrt(b) + a
which results in 16. - JavaScript comes with language-specific operators such as
increment
(++)
anddecrement
(--)
which work differently depending on whether they are pre- or post- placed in relation to a variable. - The value of the
variable
c
is decremented by 1 from 96 to 103 when--c
is applied before thevariable
is returned. - Basic programming concepts such as
variables
andmathematical operators
are building blocks for developing further techniques, and it is important to ensure no syntax errors occur.