'use strict'; declared in firebase function samples

299 views
Skip to first unread message

colto...@protonmail.com

unread,
Apr 12, 2019, 4:21:25 PM4/12/19
to Firebase Google Group
I've noticed that 
'use strict';
is declared at the top of a lot of files in
https://github.com/firebase/functions-samples but yet, when I watch different firebase videos on youtube from the firebase team, they don't use it there. I've googled what it actually means, and it makes sense that I would enable this so called "strict mode" on my production grade project, but I was wondering if anyone could shed any light on why it's not included in the videos/every sample. Maybe I'm just being anal. Maybe it's just me being a Java dev for so long that I don't understand what it is (new to this server/nodejs world of things. I also get that this probably has nothing to do with firebase as well.

Lastly though, @codingdoug talks about TypeScript and how awesome it is, and tslint and hooray more safety is good, but he doesn't enable strict mode in his video: https://www.youtube.com/watch?v=DYfP-UIKxH0

Apologies if this is a dumb question

Doug Stevenson

unread,
Apr 12, 2019, 5:00:18 PM4/12/19
to Firebase Google Group
Strict mode is quite different in TypeScript than JavaScript.  You enable it in tsconfig.json (not per source file), and it's now enabled by default in the template files created for you by the Firebase CLI when you create a new TS project.  Enabling it actually requires you to do a fair amount of extra coding to get the types right in some circumstances.  Some people might not find that necessary or helpful for smaller projects.  For larger projects, it's crucial, but that's rarely going to be the topic of a 5-10 minute video.

I can only imagine that "use strict" is not included in video resources that use plain JavaScript, because it's not required to learn Firebase.  Most Firebase videos don't attempt to teach programming best practices so much as they attempt to teach use of Firebase products.  It's up to the viewer to determine their own best practices.

Doug

colto...@protonmail.com

unread,
Apr 13, 2019, 10:52:57 AM4/13/19
to Firebase Google Group
Great. A lot of that is what I figured. I do have an additional question then, because it sounds like you're saying that TS files don't need `use strict`; for strict mode.

In the sample TS function on the github page it does include this line. Are you saying that the sample TS file is incorrect? 

Doug Stevenson

unread,
Apr 13, 2019, 11:08:10 AM4/13/19
to fireba...@googlegroups.com
I don't know what was intended there.  Perhaps you could open an issue on that repo and ask the folks who are responsible for maintaining it?

Doug

--
You received this message because you are subscribed to a topic in the Google Groups "Firebase Google Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/firebase-talk/xCSiEP82kf0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/a6f0e9db-7539-4ef8-baab-be8da95b24d0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

colto...@protonmail.com

unread,
Apr 14, 2019, 11:53:37 PM4/14/19
to Firebase Google Group
Thanks. Made an issue.
To unsubscribe from this group and all its topics, send an email to fireba...@googlegroups.com.

Hiranya Jayathilaka

unread,
Apr 15, 2019, 1:43:50 PM4/15/19
to fireba...@googlegroups.com
You can put "use strict;" in TS files, since all JS is valid TS. But you generally don't have to do this, since you can get the TS compiler to emit this instruction at compile time. Apparently there are also few error conditions you can catch at the compile time, by explicitly adding the statement to the TS files. See this post on SO for more details: https://stackoverflow.com/a/31392947/5190886

Thanks,
Hiranya

You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--

Hiranya Jayathilaka | Software Engineer | h...@google.com | 650-203-0128

Reply all
Reply to author
Forward
0 new messages