What does "use strict" do in JavaScript and why is it needed? Explanation for beginners
Hello everyone! I just started learning JavaScript and came across a strange construct: `"use strict";`. I've seen it at the beginning of some scripts and functions, but I don't understand why it's needed and what it does.\n\nHere's an example of code that works for me without `"use strict"`:\n\n```javascript\nx = 10; // I didn't declare the variable with var, let or const\nconsole.log(x); // Outputs 10\n```\n\nBut when I add `"use strict"`:\n\n```javascript\n"use strict";\nx = 10; // Error: x is not defined\nconsole.log(x);\n```\n\nWhy does the code work in the first case but throws an error in the second? I've heard that `"use strict"` makes code "safer", but I don't understand what exactly this safety consists of. And another question: should I always use it? Maybe it only slows down the code?\n\nPlease explain for beginners: