DEV Community

Deva I
Deva I

Posted on

Detail About These Interview Questions: 1.What is Javascript 2.Data types in Js and Difference Between Primitive and Non Primitive 3.Variable in js

1.What is Javascript:

◾Java script is a high level programing language that used alongside HTML and CSS.

◾It's a object oriented programming language.

◾It is used to define the behaviour of the HTML and CSS,

◾Java script is a most widely used frontend language in the world wide.

◾It is used for interact web application and supports both client side and server side development.

◾Client side means code runs on the user's computer and server side means it's runs on the web browser.

◾JavaScript is a single-threaded language that executes one task at a time.

◾Java script was created by BRENDON EICH in 1995.He's a computer programmer and technology executive.

◾Brendon takes only 10 days to create java script.

◾Java script mainly used browsers,not only browser also on servers, mobile apps and AI tools.

1.Why this language has the name of Java script?

✓ In the initial stage it was named by "MOCHA" and later renamed "LIVE SCRIPT"

✓ Then they conclude the popularity of JAVA language at the time,so its inspired JAVA language to renamed "JAVA SCRIPT".

2.Why java script is a scripting language?

✓ Java script does not need any compiler to run this code,they run on runtime browsers

✓ It is interpreted line by line execution.

✓ Example Java code need a compiler to read the code to machine language(binary) and then to compiled servers,but javascript does not need compilers to convert machine language they directly runs on browsers.

✓ Python is one of the most popular scripting languages. Known for its simple syntax and readability

2.What are the data types are in javascript?

∆ Data types are two types,they are
1.primitive data type
2.non primitive data type

∆ Javascript using 8 primitive data types,they are Number,Boolean, Bigint,String, Undefined,Null,Nan and Symbol.

Number:
✓ Its using to denote numbers like
Ex:19,12,4,2

Boolean:
✓ boolean denoted by true or false.

Bigint:
✓ Normally integer values are number,on the other hand bigint means big numbers.
Ex:2527788373782,2773993736.

String:
✓ Strings are set of characters enclosed single''or double""quotes.
Ex:"Deva",'blog'.

Undefined:
✓ Undefined is variable can be exist but not value assigned

Null:
✓ Null is denoted by empty value or 0 value.

Symbol:
✓ This used to unique symbol like percentage,greater than and lessthan etc.

∆ Non primitive data types are object, array and function.

Object:
✓ Object is a collection of key value pairs used to store data and entities.

✓ Denoted using curley braces{}

Ex:

const user = { name: "Deva", age: 22 };
console.log(user.name);// Output: Deva
Enter fullscreen mode Exit fullscreen mode

Array:
✓ Array is one of the object and used for storing multiple elements in a single container.

✓ Arrays are denoted in square brackets[].

const colors = ["red", "green", "blue"];
console.log(colors[0]); // Returns red
Enter fullscreen mode Exit fullscreen mode

Function:
✓ A function is a reusable block of code designed to perform a specific task

function welcome(name) {
  return "Hello, " + name;
}
console.log(welcome("Deva"));// Output: Hello Deva
Enter fullscreen mode Exit fullscreen mode

Difference Between Primitive and Non Primitive Data Types:

Primitive Data types:

Immutable: Values cannot be changed.

◾ Immutable means if the value reassign does not replace a memory of older one's.Rather than creates a new memory to store the value.

EXAMPLE:

let i = 10;
    i = 12;
Enter fullscreen mode Exit fullscreen mode

🔹In the above example the variable are declared and initialize the value 10.

🔹Then reassign the value 12.

🔹In this situation first memory creates and assign the value 10.

🔹Next the reassign value 12 is not assigned the memory of value 10.

🔹It creates a new memory and stores that value.

◾Storage:Stores by values in the stack.

🔹Every value stored by stack order
line by line.

🔹First value stored and then second value stored above the first value.

◾ Comparison:Compared by actual value.

EXAMPLE:

OUTPUT:

🔹It's compared by values (i(10)==j (10))
Prints true.

◾Methods:Do not have any methods but use the wrappers.

◾Starts with a lowercase.

Non Primitive Data types:

◾Mutable:Values can be changed or modified.

◾Storing:Storing by the heap.

🔹Does not follow the any order store a heap order.

◾Comparison:Compared by memory reference or address.

EXAMPLE:

🔹In this program the array values i = [10] and j = [10] is have the same value 10.

🔹But [10] = [10] are not take the value, it takes the memory address of the value.

🔹So it's returns the false.

OUTPUT:

◾Can have the methods and properties.

◾ It's only starts with a uppercase.

What is Variables:

◾Variables is a data containers

◾Variables are used to store data values.

◾The variables can be stored 4 different ways how the values should behave.

◾Older Javascript:
🔹Using var
🔹Automatically
(Both are not recommended)

◾Modern Javascript:
🔹Using let
🔹Using const

Using the let:


🔹i contains the value 5
🔹j contains the value 6
🔹k adds the i and j stores the value 11.

Using the const:


🔹i contains the value 7
🔹j contains the value 3
🔹k adds the i and j stores the value 10.

JAVASCRIPT IDENTIFIERS:

◾ Variables are identified with unique names called identifiers.

◾The rules for creating a name are:

🔹Names can contain letters, digits, underscores, and dollar signs.

🔹Names must begin with a letter, a $ sign or an underscore (_).

🔹Names are case sensitive ,because capital X is different from small x.

🔹Reserved  JavaScript  keywords like `const`, `let` `import`,`export` cannot be used as names.
Enter fullscreen mode Exit fullscreen mode

Javascript Underscore(_):

◾The underscore is treated as a letter in JavaScript names.


Javascript Dollor sign $:

◾The Dollor sign also treated as a letter in JavaScript names.


DECLARING A JAVASCRIPT VARIABLES:

◾Creating a variable in JavaScript is called declaring a variable.

◾Using let and const keywords to declare a variable in javascript.

Declaring a Variable Using let:

let Phonename = "Realme";
Enter fullscreen mode Exit fullscreen mode

🔹After the declaration, you'll not assign the value it is undefined

🔹assign a value to a variable using equal = (assignment operator)

🔹It's better to assign the value while you declared a variable.

Declaring a Variable Using const:

◾Always use const if the value should not be changed.

const Phonename = "Realme";``
Enter fullscreen mode Exit fullscreen mode

When to Use var, let, or const?

◾Always declare a variables

◾Always use const, if the value should not be changed.

◾Only useletif you cannot use const.

◾Never used varand declare variable automatically.

Top comments (2)

Collapse
 
jonrandy profile image
Jon Randy 🎖️

JS has 7 primitive types. The type of NaN is Number.

Collapse
 
deva_i_932c8869ada96d4c9f profile image
Deva I

Thanks for your information👍. I'll change it.