Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

    %s – string
    %i or %d – integer
    %o or %O – object
    %f – float
Why were these ever specific types, instead of just one option that looks at the parameter type?


I could see both, but things like integer vs float couldn't be determined from the type, since you just have the single `number` type. That being said, you could just convert to an int on the value you're passing in rather than having the interpolation do it for you. Same thing with object vs string, you could pass in `obj.toString()` instead of just `obj` with an `%s`


Probably as a remnant of C's printf? Python has the same for its string formatting.


> parameter type

laughs in JS




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: