How to highlight code inside verbatim environment?

I am writing a book containing tutorials and I need to show code:

Write this:

\begin{verbatim}
function doit() {
console.log("Hello");
}
\end{verbatim}

\begin{verbatim}
function doit() {
var s = "Hello";
console.log(s);
}
\end{verbatim}


I would like to highlight var s = "Hello"; so that it is clear it is the new code added. I would like to set a different color for this text so the new line appears black and the rest appears grey.

How do I achieve this?

This is with a very standard LaTeX document, so I did not include the whole file. fg

Here is an option with fancyvrb where you can change the formatting of specific lines; the code should be self-explanatory:

\documentclass{article}

\usepackage{fancyvrb,xcolor}

\begin{document}

Write this:

\begin{Verbatim}
function doit() {
console.log("Hello");
}
\end{Verbatim}

\renewcommand{\FancyVerbFormatLine}[1]{%
\ifnum\value{FancyVerbLine}=2
\textcolor{red}{#1}% Format specific line
\else
#1% Else, do nothing different
\fi
}
\begin{Verbatim}
function doit() {
var s = "Hello";
console.log(s);
}
\end{Verbatim}

\renewcommand{\FancyVerbFormatLine}{}% Clear how lines are formatted differently
\begin{Verbatim}
function doit() {
var s = "Hello";
console.log(s);
}
\end{Verbatim}

\end{document}


It should work for elementary setups and small code formatting.

\documentclass{article}
\usepackage{soul,listings,xcolor}

\lstnewenvironment{teX}[1][]
{\lstset{language=[LaTeX]TeX}\lstset{escapeinside={(*@}{@*)},
numbers=left,numberstyle=\normalsize,stepnumber=1,numbersep=5pt,
breaklines=true,
%firstnumber=last,
%frame=tblr,
framesep=5pt,
basicstyle=\normalsize\ttfamily,
showstringspaces=false,
keywordstyle=\itshape\color{blue},
%identifierstyle=\ttfamily,
stringstyle=\color{maroon},
rulecolor=\color{black},
xleftmargin=0pt,
xrightmargin=0pt,
aboveskip=\medskipamount,
belowskip=\medskipamount,
backgroundcolor=\color{white}, #1
}}
{}
\begin{document}

Write this:

\begin{teX}
function doit() {
console.log("Hello");
}
\end{teX}