---
title: "Discussion on \"TypeScript private vs Native JS Private Fields (#)\" | Hashnode"
description: "Discussion on \"TypeScript private vs Native JS Private Fields (#)\". Learn why TypeScript's private keyword fails at runtime and how native JavaScript # private fields provide true runtime isolation and security."
url: "https://hashnode.com/posts/typescript-private-vs-native-private-fields/6ae74033f9684b74a6d6909c"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [TypeScript private vs Native JS Private Fields (#)](https://doogal.dev/typescript-private-vs-native-private-fields?utm_source=hashnode&utm_medium=feed)

Learn why TypeScript's private keyword fails at runtime and how native JavaScript # private fields provide true runtime isolation and security.

Nov 1 · 4 min read · doogal.dev  
Read the article

-   [#typescript](https://hashnode.com/tag/typescript)
-   [#javascript](https://hashnode.com/tag/javascript)
-   [#webdevelopment](https://hashnode.com/tag/webdevelopment)
-   [#softwareengineering](https://hashnode.com/tag/softwareengineering)

## Written by

[Doogal Simpson](https://hashnode.com/@doogal)

@doogal

  
[View profile](https://hashnode.com/@doogal)

"hey doogal, what is .... ?"

## Responses 2

Markdown supported · ⌘↵ to post

[Julian Neagu](https://hashnode.com/@julianneagulab)

[Nov 4](https://hashnode.com/posts/typescript-private-vs-native-private-fields/6ae74033f9684b74a6d6909c/comment/6aeb199762e01d957af398b4)

One thing worth remembering is that private fields don't automatically make secrets safe. # stops outside code from reading the field, but API keys still need proper handling outside the class too.

[SMTasker](https://hashnode.com/@smtasker)

[Nov 3](https://hashnode.com/posts/typescript-private-vs-native-private-fields/6ae74033f9684b74a6d6909c/comment/6ae9d137aa3f6b190da45355)

One useful addition to the JSON.stringify example is a custom toJSON method. That method runs inside the class and can deliberately return a #field, so private fields do not guarantee that an instance's serialized output contains no secrets. An explicit public-data projection is still a separate decision.
