Sitemap

JavaScript Questions Part -1

3 min readJul 13, 2017

--

This is my first blog post, so I want to start from very basic JavaScript questions. If your score is not 10/10 you need to read a JavaScript book from chapter one, page one. JavaScript is tricky and dirty sometime, you should know it’s bad part to avoid them.

Press enter or click to view image in full size

Q.1 How many basic datatype in JavaScript ?

Q.2 What is the difference between Primitive and Non-primitive datatypes in JavaScript ?

Q.3 What is the difference between == & === ?

2 == '2';  // true or false
2 === '2'; // true or false

Q.4 How arithmetic operation works between different data types ?

var x = 2 + '2';
var y = 2 - '2';
var a = '2a' + 2;
var b = '2a' - 2;

Q.5 What “typeof” operator will return ?

typeof null;
typeof NaN;
typeof [];

Q.6 What are the Falsy values in JavaScript ?

Q.7 What “delete” operator will return ?

var x = 1;delete x;

Q.8 What is the type of Object, Primitive or Non-primitive ?

var foo = {};
var bar = {};
foo == bar; // true/false
foo === bar; // true/false

Q.9 How parseInt function works ?

parseInt('2a'); 
parseInt('a2');

Q.10 What will Number() constructor will return ?

Number('2a'); 
Number('a2');

Let’s go through answers an explanations

Get Dev Negi’s stories in your inbox

Join Medium for free to get updates from this writer.

A.1 There are six datatypes in JavaScript.

Number, String, Boolean, Undefined, Null, Object

A.2 Primitive types are simple data types, Non-Primitive are reference type

Number, String, Boolean, Undefined, Null // Primitive
Object // Non-primitive

A.3 == compares only value and === compares value and type also

2 == '2' // true, both values are equal 
2 === '2' // false, because LHS is type Number and RHS is String

A.4 + operator is used for both concatenation and addition, but when used with a string, defaults to concatenation. — operator cannot be used on strings, so its operands are converted to numbers.

2 + '2';  // '22'
'2' - 2; // 0

A.5 typeof operator can return these possible values as string

string, number, boolean, undefined, object, function, symbol (ES6) typeof null; // object
typeof NaN; // number
typeof []; // object

A.6 JavaScript has 6 Falsy values

false, null, undefined, NaN, '', 0

A.7 delete operator returns true/false.

var x = 1;
delete x; // false
y = 1; // creates a property in window object
delete y; // true

A.8 Objects are reference type, if a new object is created from a Object constructor it creates a new reference.

var x = {foo: 'foo'};
y = x;
y.foo = 'bar';
x.foo; // bar
var y = {};
var z = {};
y == z; // false

A.9 The parseInt function produces an integer value dictated by interpretation of the contents of the string argument according to the specified radix. Leading white space in string is ignore.

parseInt(string, radix); //  default radix is 10parseInt('22'); // 22
parseInt('2a'); // 2
parseInt(' 2'); // 2;
parseInt('a2'); // NaN

A.10 The Number constructor is the Number intrinsic object and the initial value of the Number property of the global object. When called as a constructor, it creates and initializes a new Number object. When
Number is called as a function rather than as a constructor, it performs a type conversion.

Number('2');   // 2
Number('2a'); // NaN
Number('a2'); // NaN
new Number(3) == 3; // true

--

--