let instructor = 'James';
instructor = 'Richard';
console.log(instructor);

The output is “Richard”

Use cases

The big question is when should you use  let  and  const ? The general rule of thumb is as follows:

  • use  let  when you plan to reassign new values to a variable, and
  • use  const  when you don’t plan on reassigning new values to a variable.

What about var?

Is there any reason to use  var  anymore? Not really.

There are some arguments that can be made for using  var  in situations where you want to globally define variables, but this is often considered bad practice and should be avoided. From now on, we suggest ditching  var  in place of using  let  and  const .

The right use:

/*
* Programming Quiz: Using Let and Const (1-1)
*/
const CHARACTER_LIMIT = 255;
const posts = [
"#DeepLearning transforms everything from self-driving cars to language translations. AND it's our new Nanodegree!",
"Within your first week of the VR Developer Nanodegree Program, you'll make your own virtual reality app",
"I just finished @udacity's Front-End Web Developer Nanodegree. Check it out!"
];
// prints posts to the console
function displayPosts() {
for (let i = 0; i < posts.length; i++) {
console.log(posts[i].slice(0, CHARACTER_LIMIT));
}
}
displayPosts();

Output:

#DeepLearning transforms everything from self-driving cars to language translations. AND it's our new Nanodegree!
Within your first week of the VR Developer Nanodegree Program, you'll make your own virtual reality app
I just finished @udacity's Front-End Web Developer Nanodegree. Check it out!

Source: https://www.udacity.com/course/es6-javascript-improved–ud356