4

Can someone help me to understand, What is difference between filename.js and ./filename.js

(note: While we include in html or any js file)

robertklep
  • 198,204
  • 35
  • 394
  • 381
asishkhuntia
  • 417
  • 1
  • 4
  • 7
  • @akhuntia -- can you show a few lines of code where you use the file name -- the correctness of the answer depends on where the filename is specified. – Soren Aug 20 '17 at 07:44
  • var moduleA = require("./module-a.js"); var moduleB = require("module-b.js"); – asishkhuntia Aug 20 '17 at 16:07

4 Answers4

5

As far as I know, there are no differences: both point to the file named filename.js in the current directory.

Andrew Bedford
  • 176
  • 1
  • 7
0

filename.js refers to a js while residing in the current directory. ./filename.js means that in the current directory a filename.js resides.

So, basically there is no difference but when including, to give relative path you must use "./filnemae.js".

Asim
  • 1,430
  • 1
  • 22
  • 43
0

Path can be relative or absolute. (./) means current directory, so if you are in a directory called test and you use ./page.js it means the full path is test/page.js

The second example page.js searches for a page with that name in the current directory.
Basically there are the same as long as you are referring to the file in same folder(test).

Zaheen
  • 821
  • 9
  • 11
0

there's no use is stating "./filename.js" over "filename.js". It's a forgiven coding mistake more than a convention or a sort of standard. They will both create a (relative) path which will point to the [current directory]"filename.js".

I guess, what you are looking for is the "../filename.js" r.p. (relative path) syntax.

This is a shorthand and a correct syntax for r.p., pointing to the parent folder of the current path.

Let's say, your current path is:

"domain/home/page1/index.html"

adding "../filename.js" will produce:

"domain/home/filename.js"

whereas, "filename.js" will produce:

"domain/home/page1/filename.js".

Bekim Bacaj
  • 5,707
  • 2
  • 24
  • 26