Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

VSCode Writing Code

VSCode Writing Code

VS Code has built-in support for many languages including JavaScript, TypeScript, HTML, and CSS.

In this chapter, we will create a JavaScript code file and use some of the code editing features provided by VS Code.

VS Code supports multiple programming languages. In later chapters, we will also install the Python language extensionto add support for other languages.

1. Create a JavaScript file and write code

In the Explorer view, create a new file named app.js and enter the following JavaScript code:

Example

function

sayHello

(

name

)

{

  console.

log

(

'Hello, '

name

)

;

}

sayHello

(

'VS Code'

)

;

**Code autocomplete (IntelliSense):** When you start typing code, code completion suggestions pop up. Use the ↑ or ↓ arrow keys (Up/Down) to navigate the suggestions, and press Tab to select and insert the chosen suggestion.

**Syntax highlighting:** Note the formatted display of the code (syntax highlighting), which helps distinguish different parts of the code and improves readability.

Use Code Actions

When you place the cursor on the string 'Hello,', you will see a small light bulb icon, indicating that a Code Action can be applied.

You can also use the shortcut ⌃Space to open the light bulb menu.

Click the light bulb icon, then select Convert to template string.

Code Actions provide quick fix suggestions for your code.

In this example, the Code Action converts string concatenation:



"Hello, " + name

into a template string:



`Hello, ${name}`

A template string is a special syntax in JavaScript that allows expressions to be embedded in strings.

The converted code is as follows: