0
0
Node.jsframework~20 mins

path.extname for file extensions in Node.js - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Path Extname Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
What is the output of path.extname for a simple file?
Given the following Node.js code using path.extname, what will be printed to the console?
Node.js
import path from 'path';
console.log(path.extname('photo.jpg'));
A'.jpg'
B'.photo'
C'photo.jpg'
D''
Attempts:
2 left
💡 Hint
Remember, path.extname returns the extension including the dot.
Predict Output
intermediate
1:30remaining
What does path.extname return for a file with multiple dots?
What will be the output of this code snippet?
Node.js
import path from 'path';
console.log(path.extname('archive.tar.gz'));
A''
B'.tar.gz'
C'.tar'
D'.gz'
Attempts:
2 left
💡 Hint
The extension is the substring after the last dot.
Predict Output
advanced
1:30remaining
What is the output of path.extname for a hidden file?
Consider this code. What will it print?
Node.js
import path from 'path';
console.log(path.extname('.env'));
A''
B'.'
C'.env.'
D'.env'
Attempts:
2 left
💡 Hint
Hidden files start with a dot but may not have an extension.
Predict Output
advanced
1:30remaining
What does path.extname return for a directory path ending with a dot?
What will this code output?
Node.js
import path from 'path';
console.log(path.extname('/folder.name/.hiddenfile'));
A'.hiddenfile'
B''
C'.name'
D'.file'
Attempts:
2 left
💡 Hint
The extension is based on the last part of the path, not directories.
Predict Output
expert
2:00remaining
What is the output of path.extname for a filename with trailing dot?
Analyze this code and choose the correct output:
Node.js
import path from 'path';
console.log(path.extname('filename.'));
A'.filename'
B''
C'.'
D'filename.'
Attempts:
2 left
💡 Hint
The extension includes the last dot and characters after it, even if empty.