IES: JS-deck 3 Flashcards
1
Q
JS “enum”
A
- JS keyword
- JS significant: avoid in variable/function names
- Used to define a predefined list.
- Example
~~~
const fruits={
APPLE: ‘apple’,
BANANA: ‘banana’,
Orange: ‘orange’,
}
let fruit =fruits.APPLE
if(!fruit){
throw new Error(‘ fruit is not defined ‘)
}
switch( fruit ){
case fruit.APPLE: alert(“This is an apple.”);
break;
case fruit.BANANA: alert(“This is a banana.”);
break;
case fruit.ORANGE: alert(“This is an orange.”);
}
~~~
2
Q
JS “eval”
A
- JS keyword
- JS significant: avoid in variable/function names
- Used to evaluate a specified string. The eval use as a global function eval().
- Example
~~~
function fun( ) {
var str1=2;
var str1=3;
var res = eval(new String(str1 + str2));
document.write(res);
}
fun();
~~~
3
Q
JS “export”
A
- JS keyword
- JS significant: avoid in variable/function names
- Used to export objects, functions or values from the module so that can be used in another program with the help of import statement.
- Example
~~~
export let var fruits = [“apple”, “banana”, “orange”];// export an array
export const fruit= “apple”;// export a constant
~~~
4
Q
JS “extends”
A
- JS keyword
- JS significant: avoid in variable/function names
- Used in class declarations to create a class that inherits another class.
- Example
~~~
class Employee extends Person {
constructor(name, eid, salary) {
super(name);
}
get incsalary() {
return this.salary * 0.2;
}
}
~~~
5
Q
JS “false”
A
- JS keyword
- JS significant: avoid in variable/function names
- Used to store or represent primitive data type Boolean ‘false’.
- Example
var inp = false;
6
Q
JS “final”
A
- JS keyword
- JS significant: avoid in variable/function names
- JavaScript does not have a final keyword
- Achieve similar behavior using const to declare variables that hold primitive values (numbers, strings, booleans) that shouldn’t be reassigned
7
Q
JS “finally”
A
- JS keyword
- JS significant: avoid in variable/function names
- Used in exception handling, finally block of code always execute regardless of whether the error is generating or not.
- Example
~~~
Var i=1
try {
if(i == “”) throw “is Empty”;
if(x > 0) throw “positive”;
if(x < 0) throw “negative”;
}
catch(msg) {
message.innerHTML = “Input “ + msg;
}
finally
{
alert(“This is a finally code, which always execute.”);
~~~
8
Q
JS “float”
A
- JS keyword
- JS significant: avoid in variable/function names
- In JavaScript, a reserved keyword, but it’s not used to define a floating-point data type
- This data type is used to represent numbers that have a fractional part or to represent very large or small numbers, where fixed-point representation would result in an impractical number of digits.
9
Q
JS “for”
A
- JS keyword
- JS significant: avoid in variable/function names
- Used to define a loop, for loop to repeatedly execute a block of code until a condition true.
- Example
~~~
for(var a=0; a<=10; a++) {
document.write(“The loop is running for “ + a + “ times”);
}
~~~
10
Q
JS “function”
A
- JS keyword
- JS significant: avoid in variable/function names
- Used to define a function to execute a block of code.
- Example
~~~
var func = function(){
return “Hello”;
}
alert(func());
~~~
11
Q
JS “goto”
A
- JS keyword
- JS significant: avoid for variable/function names
- return execution control to a specific location
- Ex.
~~~
var no=0;
sposition
document.write(“ something print here “);
no++;
if(no < 10) goto sposition;
~~~
12
Q
JS “if”
A
- JS keyword
- JS significant: avoid for variable/function names
- Used to define a conditioned construct. if the statement is used to run a block of code if the condition is true.
- Example
~~~
var date = new Date();
var day = date.getDay(); // Sunday Saturday : 0 6
if(day==5) {
alert(“This is weekend!”);
} else {
alert(“This is non-weekend!”);
~~~
13
Q
JS “implements”
A
- JS keyword
- JS significant: avoid in variable/function names
- Used to implement the interface in a class.
- Example
~~~
interface car
method drive(whichSpeed)
method break( )
class car1 implements car
~~~
14
Q
JS “import”
A
- JS keyword
- JS significant: avoid in variable/function names
- Used to import the module in the javascript program.
- Example
import * as alias from 'https://cdn.educba.com/modules/mymodule.js';
15
Q
JS “in”
A
- JS keyword
- JS significant: avoid for variable/function names
- It is an operator returns true if the specified property is present in the specified object, else it returns false.
- Example
~~~
var fruits={f1: “apple”, f2: “banana”, f3: “orange”};
// output as true expected
console.log(‘apple’ in fruits);
~~~