What does "./" mean in javascript?

I understand “…/” takes a step out of the current directory. Not sure what “./” means.

For example:

gulp.task('sass', function () {
    gulp.src('./css/src/*.scss')
        .pipe(sass())
        .pipe(gulp.dest('./css'));
});

I think it means ‘stay here’ . i.e. the current directory

e.g. These are the same.

./images/pic.jpg
images/pic.jpg

I believe the ./ is redundant but I’m sure someone will enlighten me if I am wrong :slight_smile:

1 Like

I think you are right, and I wonder what the point of having it is. I would think there would be a greater risk making a typo and entering …/ instead of ./ and then ending up one level higher.

1 Like

I agree. I also have no idea why the documentation/tutorials I’m reading use that.

Unless you use absolute paths (eg. http://example.com/images/logo.png) there is a difference for relative paths.

  • /images/logo.png - folder with the file is in the root folder
  • …/images/logo.png - folder with the file is in the parent folder
  • ./images/logo.png - folder with the file is in the current folder

I believe so as well but it is built into the operating system so it works in all languages regardless of whether it is redundant (as with JavaScript) or where it isn’t redundant (as with references in include files on the server where no ./ means the current folder and with ./ refers to the folder that the main script is in).

1 Like

It mean runs the script from the current folder. To run from parent folder use ‘…/’

Several people have already said that. The difference is that some languages such as JavaScript run from the current folder even without the ./ while other languages such as PHP can have two current folders at the same time with which is being accessed determined by whether the reference uses ./ or not.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.