Hằng năm Thanh toán theo năm và được miễn phí 2 tháng với mọi gói trả phí. Xem các gói
Đăng nhập Bắt đầu miễn phí

Chuyển đổi mã nguồn

Đầu vào
Mã nguồn
function add(a, b) { return a + b; }
Kết quả mẫu Tạo ngày 27 tháng 10 2026

export function add(a: number, b: number): number { return a + b; }

Notes:

  • The TypeScript version explicitly accepts and returns number.
  • Unlike the JavaScript original, calls with strings or other non-number values are rejected at compile time.
  • TypeScript types are erased at runtime, so JavaScript callers can still pass incompatible values unless runtime validation is added.
  • number includes floating-point values, NaN, and Infinity.
  • JavaScript’s usual numeric behavior still applies, including floating-point precision issues and coercion at runtime.
Dùng mẫu này Chuyển đổi mã nguồn Biểu mẫu mở sẵn đầu vào của ví dụ này; bạn có thể đổi bất cứ gì.