So I am preparing now to start studying Lagrangian and Hamiltonian mechanics with Marion's book on classical dynamics. It is the first time I encounter the formal definition of vector and scalar, and I found it hard to understand.
First of all, the definition of vector: correct me if I am wrong, but what I have understood is that, if a set of quantities, $A_1, A_2, A_3$ for three-dimensions, transforms as a point under a rotation transformation, then we call $\vec{A}=(A_1, A_2, A_3)$ a vector. In summary, a vector's components transform as a point under a coordinate rotation.
The definition I don't quite understand is the definition of a scalar. It is said that a scalar is a quantity that remains invariant under a coordinate rotation. How can one understand this definition for, for example, temperature? How can a scalar be expressed in terms of the coordinate we are in?
I would appreciate help in understanding these concepts, thanks in advance!

Scalars
To a mathematician, a scalar is just an element of a (scalar) field such as the field of the real numbers $\mathbb{R}$ or the field of the complex numbers $\mathbb{C}$.
To a physicist, a scalar is a real number characterizing a certain physical property at a given point (and time) in physical space, such as the temperature at that point. The temperature at a given point $P$ in physical space must be the same number whatever coordinate system you choose! You could say the "temperature function" I'm describing here is a "physical" function, that is, it assigns a real number to a given point $P$ in actual, "physical" space.
Mathematically, however, such a "physical" function will in general be represented by different "mathematical" functions $T$ and $\overline{T}$ in different coordinate systems $Oxyz$ and $\overline{O}\,\overline{x}\,\overline{y}\,\overline{z}$, such that $T(x,y,z)=\overline{T}(\overline{x},\overline{y},\overline{z})$. These functions assign a real number to a given triple of real numbers representing the point $P$ in the respective coordinate systems, i.e. they are functions in the mathematical sense.
An example is the following. Suppose we have two coordinate systems $Oxy$ and $O\,\overline{x}\,\overline{y}$ in "two dimensional physical space", related as follows: $$\begin{pmatrix}\overline{x}\\\overline{y}\end{pmatrix}=\begin{pmatrix} \cos\theta&\sin\theta\\ -\sin\theta&\cos\theta \end{pmatrix}\begin{pmatrix}x\\y\end{pmatrix},\quad\text{or equivalenty}\quad \begin{pmatrix}x\\y\end{pmatrix}=\begin{pmatrix} \cos\theta&-\sin\theta\\ \sin\theta&\cos\theta \end{pmatrix}\begin{pmatrix}\overline{x}\\\overline{y}\end{pmatrix}$$ for some given angle $\theta$. This means that the $\overline{x}$ and $\overline{y}$ axes are rotated over an angle of $\theta$ compared to the $x$ and $y$ axes (following the right hand rule). Suppose the temperature at a point $P$, represented in the $Oxy$ system by the coordinates $(x,y)$, is given by $T(x,y)=x+y$. Then obviously $T(x,y)\neq T(\overline{x},\overline{y})$; we need a new function $\overline{T}$ in $O\,\overline{x}\,\overline{y}$ such that $T(x,y)=\overline{T}(\overline{x},\overline{y})$, or $$T(x,y)=x+y=\overline{T}(\overline{x},\overline{y}).$$ Hence \begin{align} \overline{T}(\overline{x},\overline{y})=x+y=\left(\cos\theta\,\overline{x}-\sin\theta\,\overline{y}\right)+\left(\sin\theta\,\overline{x}+\cos\theta\,\overline{y}\right) \end{align} or $$\overline{T}(\overline{x},\overline{y})=\left(\cos\theta+\sin\theta\right)\overline{x}+\left(\cos\theta-\sin\theta\right)\overline{y}.$$
Vectors
To a mathematician, a vector is an element of a vector space.
To a physicist, a vector is imagined to be an arrow in physical space. When viewed in two different coordinate systems (both centered at the bottom of the arrow for simplicity), the coordinates of the endpoint of the vector will in general be different. Hence one can't just describe a physical vector by the coordinates $(x_1,x_2,x_3)$ of its endpoint in just one coordinate system $Ox_1x_2x_3$: one needs to know how to obtain the corresponding coordinates $\left(\overline{x}_1,\overline{x}_2,\overline{x}_3\right)$ in a different coordinate system $O\,\overline{x}_1\overline{x}_2\overline{x}_3$. Given that the origins coincide, the rule is pretty simple: the coordinate systems will be related to each other by a rotation, described by an orthogonal matrix: $$\begin{pmatrix}\overline{x}_1\\\overline{x}_2\\\overline{x}_3\end{pmatrix}=\begin{pmatrix}O_{11}&O_{12}&O_{13}\\ O_{21}&O_{22}&O_{23}\\ O_{31}&O_{32}&O_{33}\end{pmatrix}\begin{pmatrix}x_1\\x_2\\x_3\end{pmatrix}.$$ In index notation: $$\overline{x}_i=\sum_{j=1}^nO_{ij}x_j,\quad i=1,2,3.$$ Hence a physical vector can be described as being an ordered set of numbers $(x_1,x_2,x_3)$ which transform according to the rule just stated under a rotation of the coordinate axes (an orthogonal transformation).