10 Interesting Things In JavaScript

Sourav Sarkar Emon
4 min readAug 19, 2020

JavaScript is the world’s most popular programming language. JavaScript was invented by Brendan Eich in 1995 and became an ECMA standard in 1997. Javascript is most well-known as the scripting language. As of 2012, all of the rn browsers fully support JavaScript.

To be a programmer you must know about JavaScript(Js). Because it is a core part of the programming. JavaScript is more important when you design a website user interface.

But there are some interesting facts about JavaScript. Here we’ll talk about some strange things in this language’s fun facts.

1. Programming Language Of The Web

JavaScript (JS) is a lightweight, interpreted, object-oriented language,
and is best known as the scripting language for Web pages. it’s also used in other environments as well.
JavaScript is a text-based programming language used both on the client-side and server-side that allows you to make web pages interactive.

2. JavaScript engine

JavaScript engine is a computer program that executes JavaScript (JS) code. Every browser provides a JS engine that runs the JavaScript code. This engine was a rudimentary interpreter with no optimizations. Running the JavaScript code with this engine was slow but it worked.

how js engine works

As you can see from the diagram above, the job of the first JavaScript engine was to take the JavaScript source code and compile it to the binary instructions (machine code) that a CPU can understand

3. Start with a Semicolon!

In much other time, you have to put a semicolon(;) at the end of a statement. But you can start with a semicolon(;) if you want. But it is not recommended.

;var a = 2

4. Sum of String and Numbers

If you sum a number with a string you will get this:

'500' + 1; //'5001'

Pretty strange, right?

But if you sum a string with a number then there will be no doubt:

500 + '1'; //501

5. Equal will not give you the result

In javascript to declare a variable we have to use ‘=’ but to check equality of two variables we have to use ‘==’ or ‘===’ for matching data and data types.

Here is an example:

var a = ‘100’; // assigning values to a variable with ‘=’
var b = 100; // assigning values to a variable with ‘=’
a == b; // comparing two variablesa === b; // comparing two variables, but this operator also checks datatype and compares two values.

6. Immediately-Invoked Function Expression

Look at the examples below. The first one works but the second one gives Uncaught SyntaxError: Unexpected token ).

// Works fine
var foo = function () {
//some stuff
}();

// Syntax error
function foo() {
//some stuff
}();

7. JavaScript Hijacking

There is a CSRF attack known as “JavaScript hijacking” in which a tag on an attacker’s site damages a page on the victim’s site that returns private information such as JavaScript or JSON.

JavaScript hijacking allows a hacker to gain access to data through a loophole in which an interactive Web site on a given domain can run JavaScript hosted on a different domain. For example, in a Web-based e-mail application that uses Ajax, an attacker can log in as a legitimate user. All of the contents of the e-mail inbox and address book then become available to the hacker. In addition, the hacker may send bogus e-mail messages in the name of the victim.

8. Cool Things To Do With JavaScript

Without coding many cool things we can do with javascript. Programming language JavaScript has evolved drastically over the years.

Let’s have a look at all of the cool things that YOU can do with JavaScript:

  1. Animate Websites
  2. Make Phone Apps
  3. Make Serverless Websites
  4. Make Games
  5. Flying Drones

You can do all of the above things with javascript. If you want to know more about it visit: https://flauntdigital.com/blog/cool-things-to-do-with-javascript/

9. Function Can Execute Themselves

(function() { alert('hello'); })(); //alerts 'hello'

() The syntax is simple enough: we can declare a function and immediately call it just as we call other functions, with ().

10. Undefined Can Be Defined

var someVar;
alert(someVar == undefined); //evaluates true

This is normal, but

undefined = "I'm not undefined!";
var someVar;
alert(someVar == undefined); //evaluates false!

Undefined is not actually a reserved word in JavaScript, even though it has a special meaning and is the only way to determine whether a variable is undefined.

These are some Interesting things in JavaScript. Hope you will get something new from this article.

--

--