JavaScript Was So Bad They Had To Add A Second Mode To Fix It

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ก.ย. 2024

ความคิดเห็น • 142

  •  ปีที่แล้ว +18

    I've always wondered what is the purpose of "use strict" in javascript files, but never had the time to give it enough attention or to goggle what is its purpose. Now with this video everything is clear about "use strict" and I will absolutely use it in my future javascript projects. Thank you so much for this detailed explanation with usage examples.

  • @MichaelCampbell01
    @MichaelCampbell01 ปีที่แล้ว +61

    The leading `0` for octal has roots at least as far back as the original "C" days, it wasn't "some random reason". But as a fun side effect, there is no "base 10 zero" in C, it's always octal. (Note: In java this is not the case, but both the C and C++ standards specify exactly this.)

    • @QwDragon
      @QwDragon ปีที่แล้ว +7

      0 is decimal zero, but 00 is an octal one.

    • @lawrencedoliveiro9104
      @lawrencedoliveiro9104 ปีที่แล้ว +3

      Octal numbers were pretty popular back then. They were a good fit for the PDP-11 architecture, since the fields in an instruction word for register number and addressing mode were 3 bits each. And their locations just happened to line up with individual digits in the octal integer representation of the instruction.
      One of the breaking changes in the Python 2→3 transition was moving away from a simple “0” prefix to “0o” for octal numbers.
      Personally I like the Ada based-integer style, “«n»♯xxxx♯”, where the base «n» can have any integer value from 2 to 36.

    • @harleyspeedthrust4013
      @harleyspeedthrust4013 ปีที่แล้ว +1

      0 is zero in any base. I don't know what the difference is between an "octal zero" and a "decimal zero." And whatever the reason to make 0 the prefix for octal numbers back in the day, there's no reason why that should still be a common language feature today. It's one of those foot-guns that you learn early on in your CS career and forget about until you shoot yourself in the foot with it because you put a leading zero in front of a decimal number.

    • @QwDragon
      @QwDragon ปีที่แล้ว

      @@harleyspeedthrust4013 like 30 years ago syntax highlighting was showing octal numbers (with leading zero) in a different color. But now nobody cares, just threw off this feature. But everyone is complaining how confuzing they are...

    • @harleyspeedthrust4013
      @harleyspeedthrust4013 ปีที่แล้ว +1

      @@QwDragon It's not confusing at all, it's just obscure. It's the kind of thing that you forget about until you stumble upon it because it bites you in the ass. Most people aren't going to use octal literals so they almost forget that it's a thing

  • @re.liable
    @re.liable ปีที่แล้ว +22

    learning the modern JS, strict mode has been effectively the default for me as I've always set my scripts as modules

  • @trappedcat3615
    @trappedcat3615 ปีที่แล้ว +13

    It was so bad, TypeScript was created.

  • @christopheanfry2425
    @christopheanfry2425 ปีที่แล้ว +6

    Adding type=“module” in script tag will also use the defer attribute by default

  • @louvethomas
    @louvethomas ปีที่แล้ว +15

    Thank you so much for this explanation, I never paid attention to that use strict instruction. Now that I'm trying to teach some JS to new employees in the company I'm working in, it will help ensure they learn properly before we switch to TS

    • @NotKilgamesh
      @NotKilgamesh ปีที่แล้ว +1

      Are you all hiring? 😅

    • @louvethomas
      @louvethomas ปีที่แล้ว +1

      @@NotKilgamesh We sometimes do, if you're in France and near Paris 😁

    • @smartphonecinematics
      @smartphonecinematics ปีที่แล้ว

      @@louvethomas Hi there, I am actually a year 3 university student from Singapore studying information systems and I will be in France, Paris from January 2023 for my exchange programme. I will be looking for an internship opportunity if your company is hiring :) PM me if interested, merci beaucoup hahah

    • @louvethomas
      @louvethomas ปีที่แล้ว +1

      @@smartphonecinematicsHello there, we mostly do web dev, but it's a big company, maybe i can pass a resume and they'll check if they are interested.

  • @nathanbanji5015
    @nathanbanji5015 ปีที่แล้ว +3

    Hi Web Dev Simplified, I truly love your videos, you are the reason why I originally got into web development. You've taught me so much in the past year and a half, and I was wondering if you could make a tutorial on implementing ads into your website. I've been trying for a while now but I can't seem to get it to work.

  • @carafachera4781
    @carafachera4781 ปีที่แล้ว +4

    I love your videos, can´t stop waching them. Thanks for all this high quality videos.

  • @ShiloBuff
    @ShiloBuff ปีที่แล้ว +8

    Your videos are always top notch and cover what I consider niche and advanced topics which is great. I recommend you to any friends who are learning javascript. Keep up the great work!

  • @yokowasis
    @yokowasis ปีที่แล้ว +2

    Why not use typescript like a normal person?

  • @broooth
    @broooth ปีที่แล้ว +3

    Or "use typescript"

  • @CJFX_
    @CJFX_ ปีที่แล้ว +1

    Could you do a tutorial on await / promises / observables (more typescript content possibly?) I've found I've needed to rely on manually adding timeouts / waits using the waituntil npm package but was wondering if there was a better way to do this? Just more DB involved content would be nice I guess

  • @mubasherali630
    @mubasherali630 ปีที่แล้ว +4

    man you are amazinggg. thats why i don't miss your video. I knew strict mode already. but that octal stuff just blew my mind. litterally i don't know how you get to know these stuff. thanks alot man. Now its my time to blewwww others mind by writing 015 xD

  • @raymondbyczko
    @raymondbyczko ปีที่แล้ว +1

    JavaScript: The Good Parts - is a good read. The behavior of 'this' is one part commented on in that book. Anyone have a timemachine to change this :)

  • @KoenVerheyen
    @KoenVerheyen ปีที่แล้ว

    That arguments[0] = ...; thingy is quirky as hell!

  • @theisoj
    @theisoj ปีที่แล้ว +2

    Thanks for this video Kyle!

  • @UnlikelyToRemember
    @UnlikelyToRemember ปีที่แล้ว

    The arguments "array" sometimes comes in handy in varargs functions.

  • @ColinRichardson
    @ColinRichardson ปีที่แล้ว +3

    I would prefer Javascript runtimes remove ASI, because, it's just annoying that people believe abusing this behavior is considered "good practice"
    Like saying "the legal limit of tread on a car tire is 1.6mm", so you should run it at that ALL THE TIME..
    Or, the legal speed limit on a road is 50mph, so I will travel that fast ALL THE TIME regardless of icy conditions or not.

    • @colinmarshall6634
      @colinmarshall6634 ปีที่แล้ว

      It's also bad for beginners. I'm in a full stack bootcamp where 90%+ of the class had never coded before. Having ASI is just setting them up to fail when they go learn java or python next. I think I'm going to start preaching strict mode in class just as a way to avoid syntax mistakes, but it seems to be good practice.

    • @ColinRichardson
      @ColinRichardson ปีที่แล้ว

      @@colinmarshall6634 Yeah, and the beginners are not going to know about the 1 or 2 pitfalls where it is 100% required to use a semicolon.

  • @SteveAB4EL
    @SteveAB4EL ปีที่แล้ว +1

    Someone at JS Central peeked at a PERL script ... *use strict;* directive.

    • @technovelodos
      @technovelodos ปีที่แล้ว +1

      Yeah. I had flashbacks to the 90s seeing this, when I first started writing web apps in Perl.

  • @weakinsane
    @weakinsane ปีที่แล้ว +1

    how to activate hidden typescript

  • @butbutmybutt
    @butbutmybutt ปีที่แล้ว

    in classes and js loaded via es modules u don't need use strict, it's active automatically

  • @Raptor-jq8jg
    @Raptor-jq8jg ปีที่แล้ว +2

    Thanks for the video!

  • @cryofwill1416
    @cryofwill1416 ปีที่แล้ว +1

    dude this is so gooood for debuggin and for me that im still learning JS its reaaaaaaaaaally good so i can write better now i feel

  • @michaelschmid2311
    @michaelschmid2311 ปีที่แล้ว

    yeah, working for a company developping ui5 and js apps we always use "strict Mode"

  • @dajac
    @dajac ปีที่แล้ว

    Thank you, Kyle. This helped me immensly.

  • @cherubin7th
    @cherubin7th ปีที่แล้ว +1

    "strict mode" looks more like "relaxed but less stupid mode".

    • @321sas
      @321sas ปีที่แล้ว +1

      😂 SHIT THATS FUNNYY

  • @Pareshbpatel
    @Pareshbpatel ปีที่แล้ว +1

    An excellent introduction to JavaScript Strict Mode. Thanks, Kyle
    {2022-10-15}

  • @gasparinizuzzurro6306
    @gasparinizuzzurro6306 ปีที่แล้ว +1

    Javascript as others 'moderns' languages like python, php is, and remain still bad regardless of every effort to improve it.
    (like typescript, flow, coffeescript etc).

  • @anaselhassani2545
    @anaselhassani2545 ปีที่แล้ว

    Worked , thanks a lot!

  • @javascript-zb8xe
    @javascript-zb8xe 4 หลายเดือนก่อน

    nice, short and clear!

  • @maheshcharyindrakanti8544
    @maheshcharyindrakanti8544 ปีที่แล้ว

    Thank you man for sharing this stuff

  • @Abu-Lutfy
    @Abu-Lutfy ปีที่แล้ว

    how do you make the console tab take all the browser space ?

  • @boem231
    @boem231 ปีที่แล้ว +2

    You can use ESLint to check your code without strict mode

  • @theodorealenas3171
    @theodorealenas3171 ปีที่แล้ว +1

    Does strict mode log errors or does it also change the behavior of the web app? If it does change the behavior, I'd imagine there are frameworks for only keeping strict mode in the dev version.

    • @lawrencedoliveiro9104
      @lawrencedoliveiro9104 ปีที่แล้ว

      Errors appear in the browser console. The script will also abort.

    • @theodorealenas3171
      @theodorealenas3171 ปีที่แล้ว

      @@lawrencedoliveiro9104 if it aborts then it shouldn't have much code per module I suspect. I find it weird I don't know.

  • @sivaramakrishnan4833
    @sivaramakrishnan4833 ปีที่แล้ว

    Thank you so much for this video ☺️

  • @sciverzero8197
    @sciverzero8197 ปีที่แล้ว +1

    I stopped using strict mode because my code would _never_ work the way I intended it to in strict mode.

  • @iorisi
    @iorisi ปีที่แล้ว +2

    Keep going forward❤️

  • @parlor3115
    @parlor3115 ปีที่แล้ว

    The last one is scary ngl

  • @syednaqvi6572
    @syednaqvi6572 ปีที่แล้ว

    awesome as always

  • @saadaqmohamed2355
    @saadaqmohamed2355 ปีที่แล้ว +1

    Every day iam watching your videos slowly 🐌 😌

  • @snake1625b
    @snake1625b ปีที่แล้ว +1

    Does typescript do all these checks anyways?

    • @ja31ya
      @ja31ya ปีที่แล้ว +1

      Typescript runs in strict mode by default, though not to be confused with the tsconfig "strict" compiler option, which is typescripts strict type checking mode.

  • @melonenlord2723
    @melonenlord2723 ปีที่แล้ว

    I have a question, maybe someone can help.
    How can you do something like how Date is implentated in js?
    You can call it without the new keyword or with the keyword and it does different things. Without it simply returns a String with the Date, with the new Keyword it logically returns an Object, but it acts like some kind of a String, so if you print it, you get the same, but without the ' ' thingies, but it's still an object that contains functions.
    So normally if you return an object, you see all the keys of this object and don't get a simple text. So it's some kind of return value, but return doesn't work with a class object. You can assign keys to a function, but this doesn't work with the new keyword. And you can't define a function and a class with the same name. So does someone know, how it can be called with and without new at the same time and how it only prints a kind of String line out as an object?

    • @colinmarshall6634
      @colinmarshall6634 ปีที่แล้ว

      As a beginner, I prefer working with unix timestamp and converting the string to a number if I need to make comparisons. I've only worked with Moment for time but that solved my problems.

  • @berrodev
    @berrodev ปีที่แล้ว +2

    Or just use typescript 😅?

  • @WBraxx
    @WBraxx ปีที่แล้ว

    I've been using the strict mode since... well... 2012ish because of a recommendation from another developer. I've read an article online that argued that later ECMA version has it enabled by default. Now, I'm glad that I still put into my code and didn't listen to the article.

    • @lawrencedoliveiro9104
      @lawrencedoliveiro9104 ปีที่แล้ว +1

      It is enabled by default (actually mandatorily) in modules.

    • @WBraxx
      @WBraxx ปีที่แล้ว

      @@lawrencedoliveiro9104 not everything we write is a module

    • @lawrencedoliveiro9104
      @lawrencedoliveiro9104 ปีที่แล้ว

      @@WBraxx Fun fact: you can put “type="module"” in an inline block directly in the HTML page.

  • @EnzoAuditore
    @EnzoAuditore ปีที่แล้ว

    Thank you for this

  • @Hari-mr1st
    @Hari-mr1st ปีที่แล้ว +1

    Each video he posts justifies the name of his channel.

  • @akshilverma
    @akshilverma ปีที่แล้ว

    Can you make a video on Shadow dom and how can one manipulate CSS in shadow dom

  • @oneawarer
    @oneawarer ปีที่แล้ว +1

    You can’t use the “with” keyword in strict mode.

    • @soniablanche5672
      @soniablanche5672 ปีที่แล้ว +1

      I'm pretty sure a lot of people don't even know what "with" is lmao

  • @boris_js
    @boris_js ปีที่แล้ว

    i see a lot of tricky interview questions here

  • @materialknight
    @materialknight ปีที่แล้ว +1

    After seeing this, I'm even more disappointed in that the ECMA guys had the balls to call this BS behavior "features" of the laguage, and treat their readers in a disgustingly condescending way for not thinking that JS is the masterpiece of design they think it is (it's a steaming piece of crap in its design, not to mention that it was left unattended and wasn't improved in over 10 years).
    From section "4.3.2 The Strict Variant of ECMAScript" of the official documentation:
    "The ECMAScript Language recognizes the possibility that some users of the language may wish to restrict their usage of some FEATURES available in the language. They might do so in the interests of security, to avoid what THEY CONSIDER to be error-prone FEATURES, to get enhanced error checking, or for other reasons of their choosing. In support of this possibility, ECMAScript defines a strict variant of the language."
    Awesome video Kyle! When I see one of your videos about a topic I already know, I always learn something new 😃👍👌

    • @AndrewTSq
      @AndrewTSq ปีที่แล้ว

      its a feature! for example I want a language that treats data as data. Then its up to me to use the data in the way that I want. If you write something on a paper, you dont declare that this is a string, and this is an integer. Cause it does not matter. What matters is how you use the data. And this is something every language should have in my opinion.

  • @Niksorus
    @Niksorus ปีที่แล้ว +1

    My gosh, JS used to be such a mess 🤣

  • @thedelanyo
    @thedelanyo ปีที่แล้ว

    Does strict mode check types just like typescript do?

    • @Laura69
      @Laura69 ปีที่แล้ว +1

      JavaScript cannot define types as we know them in other programming languages and strict mode does not add anything new to it.

  • @asagiai4965
    @asagiai4965 ปีที่แล้ว

    So strict mode is like you have more stricter teacher.

  • @blackcitadel37
    @blackcitadel37 ปีที่แล้ว

    The JavaScript bug I'd love to see fixed is it's very existence.

    • @elephant_888
      @elephant_888 ปีที่แล้ว +1

      Don’t hate on JavaScript. Whatever language you like is definitely not perfect either.

  • @rishiraj2548
    @rishiraj2548 ปีที่แล้ว

    Thanks

  • @Ctrl_Alt_Elite
    @Ctrl_Alt_Elite ปีที่แล้ว

    Can you get asked about strict mode in a junior dev interview?

    • @harmez7
      @harmez7 ปีที่แล้ว

      i hope so, because its so simple

  • @Aalii6
    @Aalii6 ปีที่แล้ว

    awesome!

  • @SoloElROY
    @SoloElROY ปีที่แล้ว

    Nice title!

  • @MrDebranjandutta
    @MrDebranjandutta ปีที่แล้ว

    Dart should've replaced JS, atleast with flutter the language has a chance now.

  • @maheshcharyindrakanti8544
    @maheshcharyindrakanti8544 ปีที่แล้ว

    ty bruu

  • @ankitshukla8640
    @ankitshukla8640 ปีที่แล้ว

    Why don't you make some tutorials in angular.

  • @izexi
    @izexi ปีที่แล้ว

    Hi, can u pls explain how to get access to selectors that have same class names or id's so u could do onclick functions or add and delete classes or styles or data-attributes with JavaScript? Thanks

    • @chinmayghule8272
      @chinmayghule8272 ปีที่แล้ว +1

      Google it.

    • @brunogonzalez8490
      @brunogonzalez8490 ปีที่แล้ว +1

      To select all DOM objects with the class ".selector" just use querySelectorAll, you can use forEach to iterate it. It will return a static nodeList, so if you change something after selecting those DOM elements the change will not reflect in the nodeList.

    • @izexi
      @izexi ปีที่แล้ว

      @@brunogonzalez8490 its hard to understand for me how to work with concrete element that has same class with forEach
      I console log them, but cant understand how to onclick function them in forEach
      Would be nice to have good explanations how to work with arrays and element in them

    • @izexi
      @izexi ปีที่แล้ว

      @@chinmayghule8272 google your life. There is a lot of trash in google when u trying to find good explanations

    • @ExileEditing
      @ExileEditing ปีที่แล้ว

      @@izexi there's a lot of good ones that usually are at the top of the page but sometimes you have to search longer or change up keywords. There should be thousands of answers on that question

  • @soniablanche5672
    @soniablanche5672 ปีที่แล้ว

    if you're using modules you are automatically in strict mode

  • @allan_archie
    @allan_archie ปีที่แล้ว

    WHY DISABLE LINE NUMBERING? MY BRAIN IS BREAKING!

  • @und0
    @und0 ปีที่แล้ว +1

    just use typescript omg

  • @hiwotina26
    @hiwotina26 ปีที่แล้ว

    Bravo!

  • @maomorin
    @maomorin ปีที่แล้ว

    Este man como le hace para ser tan inteligente

  • @harmez7
    @harmez7 ปีที่แล้ว

    lets be kind, not strict

  • @learnwithshaheb
    @learnwithshaheb ปีที่แล้ว

    awesome

  • @De-Coder1.0.0
    @De-Coder1.0.0 ปีที่แล้ว

    very usefull thing to know this morning. , but ppl please i have an issue , i am trying to use a button that was created and rendered because of an evenlistn like using a pop up button to redirect you BUT i can get it to work i tried the mutationoserver but didnt work , only thing that worked was setIntervals but that is not practical.

  • @dand4485
    @dand4485 ปีที่แล้ว +1

    Kyle, love your videos, but my first computer teacher would fail you... When showing the console.log(015) and you mention putting an O (as in Oscar...) you are putting a 0 (zero) not an 'O'... Picky picky, but should really say zero if in fact it is a zero...?

    • @0oh_no
      @0oh_no ปีที่แล้ว

      "oh" is sometimes said for zero

    • @fyfoh
      @fyfoh ปีที่แล้ว

      Quick, someone tell 007 that he's going to fail as a spy!

    • @dand4485
      @dand4485 ปีที่แล้ว

      @@0oh_no Just like ain't isn't a word. Or better yet i'll give you 1ohohohoh dollars, which in actuality is nothing.

  • @nibrocremulb3013
    @nibrocremulb3013 ปีที่แล้ว +1

    “Are you in sloppy mode?” Depends who’s asking 😏

  • @mavdotj
    @mavdotj ปีที่แล้ว +1

    Minecraft mob vote. Just kidding

    • @321sas
      @321sas ปีที่แล้ว +1

      nice

    • @mavdotj
      @mavdotj ปีที่แล้ว

      Why did I post this comment? I think I was high

    • @321sas
      @321sas ปีที่แล้ว +1

      @@mavdotj But your right

  • @mikevaleriano9557
    @mikevaleriano9557 ปีที่แล้ว +1

    FFS, just switch to typescript and don't look back.

  • @QwDragon
    @QwDragon ปีที่แล้ว +1

    Strict mode this has nothing to do with the security: first of all the code desides itself if it is writen in strict mode or not, secondly you can always access global object, there is even special globalThis word to do it. All strict mode featurtes are for catching possible bugs only.
    By the way, same argument names may be useful if you want to ignore these arguments like function (_, _, _, x) { return x }, but in strict mode you have to name them differently.

    • @lawrencedoliveiro9104
      @lawrencedoliveiro9104 ปีที่แล้ว

      Strict mode requires global names to be explicitly declared as global, among other safety features.

    • @QwDragon
      @QwDragon ปีที่แล้ว

      @@harleyspeedthrust4013 no, I haven't said such thing.

    • @lawrencedoliveiro9104
      @lawrencedoliveiro9104 ปีที่แล้ว

      @@harleyspeedthrust4013 That’s why it was introduced.

  • @rodz
    @rodz ปีที่แล้ว

    i might love JS, but brah, this is so bad

  • @almahbuby
    @almahbuby ปีที่แล้ว

    Sloppy 😳

  • @AndrewTSq
    @AndrewTSq ปีที่แล้ว +1

    more like "People were so bad coders that they had to implement this..."

    • @pupfriend
      @pupfriend ปีที่แล้ว +1

      good programmers make mistakes too

    • @AndrewTSq
      @AndrewTSq ปีที่แล้ว

      @@pupfriend Yes. Its not JS fault that there are bugs in code. Myself grow up with poking machinecodes into c64 basic. No safetybelts there.. and sometimes it did not work.. not the c64 fault :) my fault!.

    • @hexerei02021
      @hexerei02021 ปีที่แล้ว

      @@AndrewTSq cool

    • @pupfriend
      @pupfriend ปีที่แล้ว

      @@AndrewTSq The point is that even good programmers should use tools to help stop the foot gun. John Carmack was on with Lex Fridman recently. He talked about how he took one of the Id software 3d engines and analyzed it using some code quality tools. The software he analyzed was widely regarded as one of the best engineered pieces of software around. And yet, the tools he used found all sorts of issues.
      I made a comment that I think was deleted by Kyle. Something like ... JS is bit like raw dogging in a whorehouse. Without protection, you'll eventually have big problems.
      JS has lots of obscure dangers. Good and bad developers alike should use whatever they can to help protect themselves.

    • @AndrewTSq
      @AndrewTSq ปีที่แล้ว

      @@hexerei02021 I would agree if I had been good at it lol.

  • @ninjaplavi
    @ninjaplavi ปีที่แล้ว

    You deserve dislike for this clickbait :D

    • @elephant_888
      @elephant_888 ปีที่แล้ว

      Why is this clickbait?

  • @JeanDidier
    @JeanDidier ปีที่แล้ว +1

    Would got mad the day I would console.log(015) and see 13

    • @theodorealenas3171
      @theodorealenas3171 ปีที่แล้ว

      I got this mad when I did the same mistake in another language. I can't remember which one but it must have been C or Python. It was the standard back then.

    • @AndrewTSq
      @AndrewTSq ปีที่แล้ว

      thats cause you treat the number as an octal...has nothing todo with js being wierd