Let’s look at the JavaScript statement. We will go over the simple uses, as well as a deep dive into some more advanced concepts. with Note: Use of the with statement is discouraged. It can lead to strange bugs. That said, it is important to understand how it works because it may exist in legacy code. With Function Syntax From Mozilla’s definition: (expression){ statement } with : An that evaluates to an object that will become the default object inside its scope. expression expression : Code that will run with the evaluated expression as the default object statement Example car = { : } (car){ .log(color) } let color 'red' with console // prints 'red' As you can see, the car object becomes the default object in the scope. The object’s properties become available without using the ‘.’ operator. If the variable already exists in the parent scope, it will be overwritten: color = car = { : } (car){ .log(color) } let 'blue' let color 'red' with console // prints 'red' Why Shouldn’t I Use ‘With’? Using with is not recommended, and is forbidden in ECMAScript 5 . The recommended alternative is to assign the object whose properties you want to access to a temporary variable. strict mode While using can make long pieces of code easier to read due to the removal of long accessor paths, with (car.make.model){ size = width * height * length; } vs size = car.make.model.width * car.make.model.height * car.make.model.length; with let let the danger or potential bugs due to ambiguity isn’t worth it. There is an argument to be made that code will be smaller and easier to send to the browser by using ‘with’ statements. While true, the gains are negligible, especially when compared to what minified code can do. By (twitter) @wagslane Previously published at https://qvault.io/2020/01/15/javascript-with-statement-explained-a-deep-dive/ Thanks For Reading Lane on Twitter: @wagslane Lane on Dev.to: wagslane Download Qvault: https://qvault.io