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
  • 185,685
  • 31
  • 370
  • 359
asishkhuntia
  • 367
  • 1
  • 3
  • 6
  • @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.

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,322
  • 1
  • 18
  • 31
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
  • 811
  • 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,264
  • 2
  • 21
  • 26