Click here to Skip to main content
15,890,438 members
Articles / Programming Languages / Javascript
Tip/Trick

IntelliSense for JavaScript Files (.js) in Visual Studio

Rate me:
Please Sign up or sign in to vote.
4.67/5 (9 votes)
15 Oct 2014CPOL 19.6K   14   3
IntelliSense for JavaScript files (.js) in Visual Studio

Introduction

In Visual Studio, we get IntelliSense support for JavaScript in our markup files (.html or .aspx) when we include these references using the <script> tag.

JavaScript
<script src="Scripts/angular.js"></script>

<script src="Scripts/angular-route.js"></script>

But what if we are writing pure JavaScript (.js) files which will later be included in our markups. We look for IntelliSense pressing the Ctrl+Spacebar, but don’t find any and it gets really annoying, as we are so used to IntelliSense in Visual Studio.

In order to support IntelliSense in such files (.js), we have to add a /// <reference path="[file path]”> tag to our JavaScript files, to activate the IntelliSense for the referenced JavaScript file.

JavaScript
/// <reference path="../Scripts/angular.js" />

/// <reference path="../Scripts/angular-route.js" />

An example below...

Image 1

Here, we are getting expected JavaScript IntelliSense support.

Once our app.js is created, we add it to our markup as follows:

JavaScript
<script src="Scripts/angular.js"></script>
<script src="Scripts/angular-route.js"></script>
<script src="app/app.js"></script>

Our markup though would need the referenced JavaScript files included in the <script> tags as well!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
India India
Be ahead of the curve.

Comments and Discussions

 
GeneralIt's a new standard now Pin
ron0123416-Oct-14 9:20
ron0123416-Oct-14 9:20 
mate. this intellisense has been part of the ASP.NET project template in VS 2013.. in fact the all you need to is simply create a _reference.js file in the scripts folder (no need to type //reference in every single js files).
QuestionEmbedded image error in your blog... Pin
Tokinabo16-Oct-14 4:10
professionalTokinabo16-Oct-14 4:10 
AnswerRe: Embedded image error in your blog... Pin
ManishHPatil16-Oct-14 4:35
professionalManishHPatil16-Oct-14 4:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.