Compilers can optimize pretty well, even if you don't give them inline or constexpr keywords, as in the preceding example. One thing that helps them achieve performance for you is marking variables and functions as const. Perhaps even more importantly, it also helps you avoid making mistakes in your code. Many languages have immutable variables by default, which can lead to fewer bugs, code that's easier to reason about, and often faster multi-threaded performance.
Even though C++ has mutable variables by default and you need to explicitly type const, we encourage you to do so. It can really help you stop making tricky typos related to modifying a variable that you shouldn't.
Using const (or constexpr) code is part of a bigger philosophy called type safety. Let's say a few words about it.