Visual Studio Code includes built-in JavaScript IntelliSense, debugging, formatting, code navigation, refactorings, and many other advanced language features. Show
Most of these features just work out of the box, while some may require basic configuration to get the best experience. This page summarizes the JavaScript features that VS Code ships with. Extensions from the VS Code Marketplace can augment or change most of these built-in features. For a more in-depth guide on how these features work and can be configured, see Working with JavaScript. IntelliSenseIntelliSense shows you intelligent code completion, hover information, and signature information so that you can write code more quickly and correctly. Sorry, your browser doesn't support HTML 5 video.VS Code provides IntelliSense within your JavaScript projects; for many npm libraries such as See Working with JavaScript for information about VS Code's JavaScript IntelliSense, how to configure it, and help troubleshooting common IntelliSense problems. JavaScript projects (jsconfig.json)A jsconfig.json file defines a JavaScript project in VS Code. While 0 files are not required, you will want to create one in cases such as:
To define a basic JavaScript project, add a 0 at the root of your workspace:
See Working with JavaScript for more advanced 0 configuration.
SnippetsVS Code includes basic JavaScript snippets that are suggested as you type; Sorry, your browser doesn't support HTML 5 video.There are many extensions that provide additional snippets, including snippets for popular frameworks such as Redux or Angular. You can even define your own snippets.
JSDoc supportVS Code understands many standard JSDoc annotations, and uses these annotations to provide rich . You can optionally even use the type information from JSDoc comments to . Sorry, your browser doesn't support HTML 5 video.Quickly create JSDoc comments for functions by typing 5 before the function declaration, and select the JSDoc comment snippet suggestion:Sorry, your browser doesn't support HTML 5 video.To disable JSDoc comment suggestions, set 6.Hover InformationHover over a JavaScript symbol to quickly see its type information and relevant documentation. The ⌘K ⌘I (Windows, Linux Ctrl+K Ctrl+I) keyboard shortcut shows this hover information at the current cursor position. Signature HelpAs you write JavaScript function calls, VS Code shows information about the function signature and highlights the parameter that you are currently completing: Signature help is shown automatically when you type a 7 or 8 within a function call. Press ⇧⌘Space (Windows, Linux Ctrl+Shift+Space) to manually trigger signature help.Auto importsAutomatic imports speed up coding by suggesting available variables throughout your project and its dependencies. When you select one of these suggestions, VS Code automatically adds an import for it to the top of the file. Just start typing to see for all available JavaScript symbols in your current project. Auto import suggestions show where they will be imported from: If you choose one of these auto import suggestions, VS Code adds an import for it. In this example, VS Code adds an import for 9 from material-ui to the top of the file:To disable auto imports, set 0 to 1.
FormattingVS Code's built-in JavaScript formatter provides basic code formatting with reasonable defaults. The 4 settings configure the built-in formatter. Or, if the built-in formatter is getting in the way, set 5 to 1 to disable it.For more specialized code formatting styles, try installing one of the JavaScript formatting extensions from the Marketplace. JSX and auto closing tagsAll of VS Code's JavaScript features also work with JSX: You can use JSX syntax in both normal 7 files and in 8 files.VS Code also includes JSX-specific features such as autoclosing of JSX tags: Sorry, your browser doesn't support HTML 5 video.Set 9 to 1 to disable JSX tag closing.Code navigationCode navigation lets you quickly navigate JavaScript projects.
You can navigate via symbol search using the Go to Symbol commands from the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)).
RenamePress F2 to rename the symbol under the cursor across your JavaScript project: RefactoringVS Code includes some handy refactorings for JavaScript such as Extract function and Extract constant. Just select the source code you'd like to extract and then click on the lightbulb in the gutter or press (⌘. (Windows, Linux Ctrl+.)) to see available refactorings. Available refactorings include:
See Refactorings for more information about refactorings and how you can configure keyboard shortcuts for individual refactorings. Unused variables and unreachable codeUnused JavaScript code, such the else block of an 1 statement that is always true or an unreferenced import, is faded out in the editor:You can quickly remove this unused code by placing the cursor on it and triggering the Quick Fix command (⌘. (Windows, Linux Ctrl+.)) or clicking on the lightbulb. To disable fading out of unused code, set 2 to 1. You can also disable fading of unused code only in JavaScript by setting:
Organize ImportsThe Organize Imports Source Action sorts the imports in a JavaScript file and removes any unused imports: Sorry, your browser doesn't support HTML 5 video.You can run Organize Imports from the Source Action context menu or with the ⇧⌥O (Windows, Linux Shift+Alt+O) keyboard shortcut. Organize imports can also be done automatically when you save a JavaScript file by setting:
Code Actions on SaveThe 4 setting lets you configure a set of Code Actions that are run when a file is saved. For example, you can enable organize imports on save by setting:
You can also set 4 to an array of Code Actions to execute in order.Here are some source actions:
See Node.js/JavaScript for more information. Code suggestionsVS Code automatically suggests some common code simplifications such as converting a chain of 0 calls on a promise to use 1 and 2Sorry, your browser doesn't support HTML 5 video.Set 3 to 1 to disable suggestions.Enhance completions with AIGitHub Copilot is an AI-powered code completion tool that helps you write code faster and smarter. You can use the GitHub Copilot extension in VS Code to generate code, or to learn from the code it generates. GitHub Copilot provides suggestions for numerous languages and a wide variety of frameworks, and it works especially well for Python, JavaScript, TypeScript, Ruby, Go, C# and C++. You can learn more about how to get started with Copilot in the Copilot documentation. Once you have the Copilot extension installed and enabled, you can test it our for your JavaScript projects. Create a new file - you can use the File: New File command in the Command Palette (F1). In the JavaScript file, type the following function header:
Copilot will provide a suggestion like the following - use Tab to accept the suggestion: Inlay hintsInlay hints add additional inline information to source code to help you understand what the code does. Parameter name inlay hints show the names of parameters in function calls: This can help you understand the meaning of each argument at a glance, which is especially helpful for functions that take Boolean flags or have parameters that are easy to mix up. To enable parameter name hints, set 5. There are three possible values:
Variable type inlay hints show the types of variables that don't have explicit type annotations. Setting: 9Property type inlay hints show the type of class properties that don't have an explicit type annotation. Setting: Parameter type hints show the types of implicitly typed parameters. Setting: Return type inlay hints show the return types of functions that don't have an explicit type annotation. Setting: References CodeLensThe JavaScript references CodeLens displays an inline count of reference for classes, methods, properties, and exported objects: To enable the references CodeLens, set Click on the reference count to quickly browse a list of references: Update imports on file moveWhen you move or rename a file that is imported by other files in your JavaScript project, VS Code can automatically update all import paths that reference the moved file: Sorry, your browser doesn't support HTML 5 video.The
LintersLinters provides warnings for suspicious looking code. While VS Code does not include a built-in JavaScript linter, many JavaScript linter extensions available in the marketplace.
Type checkingYou can leverage some of TypeScript's advanced type checking and error reporting functionality in regular JavaScript files too. This is a great way to catch common programming mistakes. These type checks also enable some exciting Quick Fixes for JavaScript, including Add missing import and Add missing property. TypeScript tried to infer types in Type checking of JavaScript is optional and opt-in. Existing JavaScript validation tools such as ESLint can be used alongside built-in type checking functionality. DebuggingVS Code comes with great debugging support for JavaScript. Set breakpoints, inspect objects, navigate the call stack, and execute code in the Debug Console. See the Debugging topic to learn more. Debug client sideYou can debug your client-side code using a browser debugger such as our built-in debugger for Edge and Chrome, or the Debugger for Firefox. Debug server sideDebug Node.js in VS Code using the built-in debugger. Setup is easy and there is a to help you. Popular extensionsVS Code ships with excellent support for JavaScript but you can additionally install debuggers, snippets, linters, and other JavaScript tools through extensions.
Next stepsRead on to find out about:
Common questionsDoes VS Code support JSX and React Native?VS Code supports JSX and React Native. You will get IntelliSense for React/JSX and React Native from automatically downloaded type declaration (typings) files from the npmjs type declaration file repository. Additionally, you can install the popular React Native extension from the Marketplace. To enable ES6 import statements for React Native, you need to set the Does VS Code support the Dart programming language and the Flutter framework?Yes, there are VS Code extensions for both Dart and Flutter development. You can learn more at the Flutter.dev documentation. IntelliSense is not working for external libraries
ES6 Style imports are not working. When you want to use ES6 style imports but some type declaration (typings) files do not yet use ES6 style exports, then set the TypeScript compiler option
Can I debug minified/uglified JavaScript?Yes, you can. You can see this working using JavaScript source maps in the Node.js Debugging topic. How do I disable Syntax Validation when using non-ES6 constructs?Some users want to use syntax constructs like the proposed pipeline ( With Can I use other JavaScript tools like Flow?Yes, but some of Flow's language features such as type and error checking may interfere with VS Code's built-in JavaScript support. To learn how to disable VS Code's built-in JavaScript support, see . Dimana menuliskan coding JavaScript?Console Javascript dapat kita buka melalui Inspect Element->Console. Di dalam console, kita bisa menulis fungsi atau kode-kode javascript dan hasilnya akan langsung ditampilkan.
Bagaimana cara yang benar untuk menggunakan file JavaScript di HTML?Anda bisa langsung menambahkan JavaScript di HTML dengan menggunakan tag <script></script> yang mencakup semua kode JS yang Anda tulis. Kode JS yang bisa ditambahkan: di antara tag <head> di antara <body>
Bagaimana cara kerja JavaScript?Cara Kerja JavaScript pada Website
JavaScript di-embed langsung ke halaman web atau direferensikan melalui file .js terpisah. Saat pengunjung membuka halaman web, browser akan menjalankan skrip beserta kode HTML dan CSS untuk membuat halaman fungsional yang disajikan melalui tab browser.
JavaScript pakai aplikasi apa?Namun, sebelumnya Anda membutuhkan beberapa aplikasi berikut untuk mendukung Anda belajar Javascript: Web browser (Google Chrome, Firefox, atau lainnya). Teks editor (Atom, Notepad, atau lainnya). Web server, untuk menjalankan kode pemrograman.
|