From the course: Learning Visual Studio Code

Unlock the full course today

Join today to access over 23,100 courses taught by industry experts.

Refactoring code

Refactoring code

Refactoring your code is part of normal code maintenance. Visual Studio Code makes it easy for you to continuously refactor and improve your code by taking advantage of the capabilities included in different language services. The particular refactoring supported will vary based on your programming language and the extension you install. I'm going to demonstrate a few of the possible options using JavaScript. Inside this file, I've developed a very basic implementation for the ShowDiscountOffer function. It declares a variable to store a discount, it then retrieves the vacation cost from an element on the web page and multiplies it by the discount. The resulting value is then shown in an element on the page. Let's refactor this code just a bit using some of the features available in VS Code. I'll first select the line that declares a new variable for the discount. Let's imagine I want to use this value elsewhere in this file. With the code selected, a little light bulb appears just to…

Contents