DEV Community

Cover image for A reintroduction to Javascript

Posted on


A reintroduction to Javascript

Reading most of the reintroduction I didn't found anything new up until, control structures, most of the things there: Numbers,Strings,BooleansandSymbols`. However I found something very interesting and for me in the introduction section, about how JS is a misunderstood language.

Unlike most programming languages, the JavaScript language has no concept of input or output. It is designed to run as a scripting language in a host environment, and it is up to the host environment to provide mechanisms for communicating with the outside world. The most common host environment is the browser, but JavaScript interpreters can also be found in a huge list of other places

This particular piece, made me understand why Javascript is such a popular programming language and is a powerful tool for programming in general.

Control Structures
The switch statement can be used for multiple branches based on a number or string:

switch (action) {
  case 'draw':
  case 'eat':

Switch is essentially like if , else however it has a break keyword, a statement to 'break out' of the switch statement and continue to the next block of code. Without the break statement additional blocks may be executed if the evaluation matches the case value.

Starting in ECMAScript 2015, object keys can be defined by the variable using bracket notation upon being created.
~~~js {[phoneType]: 12345} is possible instead of just var userPhone = {}; userPhone[phoneType] = 12345.

Sometimes `array.length` would not equate to the number of elements inside the `array`
var a = ['dog', 'cat', 'hen'];
a[100] = 'fox';
a.length; // 101

If you do something like that, you will have 4 elements in the array, however the array.length will be 101

Javascript is very liberal with the use and declaration of the function overall. You don't have to pass parameters to the function upon declaration, you can pass several parameters and then pass a different number of arguments, upon invoking, and still JS will let you compile the code. So far as I know it is strictly prohibited in most of the languages.

Object.prototype is a little bit hard to wrap your head around this concept, however, as far as I understand a prototype is an instance of the parental method and whenever you are accessing the attributes of the prototype, the prototype is having most of the features and methods that we want the child to inherit.

You can use nested function to make your code cleaner to avoid congestion. You can also store your variables for the nested function inside the parental function, right above, that will make sure that you are not making excessive global functions.

Top comments (0)

Visualizing Promises and Async/Await 🤯

async await

☝️ Check out this all-time classic DEV post