Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Sean Templeton
12,983 PointsOctal Numbers
I was watching the Creating Numbers: Part 2 video in the javascript track. I was wondering if anyone could tell me a use for octal numbers in javascript? Why would I ever need to use it?
2 Answers
Chris McKnight
Courses Plus Student 11,045 PointsOctal numbers are used for folder and file permissions on *nix operating systems. A common use for them in javascript is when you are using nodejs on a *nix system and want to use functions from the fs (file system) module that take an octal number as a parameter. For example, you need to create a directory with the permissions 0755. You need to call fs.mkdir('folder', 0755) since the default permissions are 0777.
Christopher Geary
4,531 PointsOne thing: Octal numbers are used as a shorthand for file permissions on UNIX systems. For example, you have the permissions: rwxr-xr-x which equates to 0755 (this is octal number).
Edit: Chris beat me to it :(
Sean Templeton
12,983 PointsSean Templeton
12,983 PointsOh, ok. Didn't make the connection to file permissions. Do you know why they used octal numbers for file permissions? Is it because it makes it easy to understand?
Luke Wenke
32,294 PointsLuke Wenke
32,294 Pointseach digit is 2 to the power of 3 (8).... that means 3 independent on/off options (read-write-execute)
Sean Templeton
12,983 PointsSean Templeton
12,983 PointsAhh! Nice. Thank you so much.