Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私はexpressjsアプリを書いています。req.params.anything は常に文字列であり、数値ではありません。user_id に数値を渡すと、typeof は常に文字列であるとします。
app.get('user/:user_id', function(req, res){ console.log(typeof req.params.user_id); });
GET ユーザー/21
これは文字列をログに記録します。
req.params.x は常に文字列型ですか?
はい、すべてのパラメーターは文字列になります。
これは、expressjs から抽出されますroute.js。
route.js
var val = 'string' == typeof m[i] ? decodeURIComponent(m[i]) : m[i];
valの結果decodeURIComponentは常に文字列であるため、 は常に文字列になりmますが、 は一致した文字列の配列を返す RegExp.exec() の結果であるため、文字列であると想定しても安全ですm[i]。
val
decodeURIComponent
m
m[i]