IES: JS-deck 4 Flashcards
1
Q
JS “native”
A
- JS keyword
- JS significant: avoid for variable/function names
- In JavaScript, there’s no native keyword: the term “native JavaScript” is often used to describe:
- Built-in functionalities:
- Features and objects that are part of the JavaScript language itself or are provided by the JavaScript engine without requiring external libraries or frameworks.
- Vanilla JavaScript: Code written without the use of external libraries or frameworks.
2
Q
JS “new”
A
- JS keyword
- JS significant: avoid in variable/function names
- Used to create an object.
- Example
Employee obj = new Employee ();
3
Q
JS “null”
A
- JS keyword
- JS significant: avoid in variable/function names
- Used to represent a special data type no value.
- Example
~~~
var age = null;
alert(age);
~~~
4
Q
JS “package”
A
- JS keyword
- JS significant: avoid in variable/function names
- Used to identify java classes and to execute the java method in a javascript.
- Example
inBlock['package'] = something;
5
Q
JS “private”
A
- JS keyword
- JS significant: avoid in variable/function names
- IS an access modifier can be used with attributes, classes, constructors and methods which make it not accessible to other classes.
- Example
~~~
public class Employee {
private String efn = “Joseph”;
}
class MainClass {
public static void main(String[] args) {
Employee obj = new Employee ();
System.out.println(“Name= “ + obj.efn + “ “ + obj.lname);// gives error
}
}
~~~
6
Q
JS “protected”
A
- JS keyword
- JS significant: avoid in variable/function names
- An access modifier can be used with attributes, classes, constructors and methods which make it not accessible to other classes.
- Example
7
Q
JS “public”
A
- JS keyword
- JS significant: avoid in variable/function names
- In JS, the concept of public is not a keyword: by default, all members (properties and methods) of a class are public cooling: you don’t need any special keyword to declare them.
- Example
~~~
class Person {
constructor(name, age) {
this.name = name; // Public property
this.age = age; // Public property
}greet() { // Public method
console.log(Hello, my name is ${this.name}
);
}
}
const john = new Person(“John”, 30);
console.log(john.name); // Accessing public property
john.greet(); // Calling public method
~~~
8
Q
JS “return”
A
- JS keyword
- JS significant: avoid for variable/function names
- In JavaScript, the return keyword is used to specify the value that a function should output or “return” back to the caller.
- When a return statement is encountered within a function, the function immediately stops executing, and the specified value (if any) is sent back to the code that called the function.
- You can use return to return a value from a function. This allows you to use the result of the function’s computations in other parts of your code.
- If you don’t specify a value after the return keyword, or if you omit the return statement altogether, the function will return undefined.
- Example
~~~
function addNumbers(num1, num2) {
return num1 + num2;
}
let result = addNumbers(3, 5);
console.log(result); // Output: 8
~~~
9
Q
JS “short”
A
- JS keyword
- JS significant: avoid for variable/function names
- Belongs to the so-called future keywords by the ECMAScript specification. Has no special functionality at present but might at some future time.
- In ECMAScript 5/6, short was removed from the list of reserved words. Nonetheless for compatibility with older browsers not implementing either, you shouldn’t use it anyway.
10
Q
JS “static”
A
- JS keyword
- JS significant: avoid for variable/function names
- Used to define a static method in a class. Static methods are those methods that are not called on the object.
- Example
~~~
class Employee extends Person {
constructor(name, eid, salary) {
super(name);
}
static disp()
{
return “This is static method “
}
}
document.writeln( Employee.disp() );
~~~
11
Q
JS “super”
A
- JS keyword
- JS significant: avoid in variable/function names
- Used to call function or method of a parent class.
- Example
super.disp(); //the disp is a method of a parent class
12
Q
JS “switch”
A
- JS keyword
- JS significant: avoid in variable/function names
- Used in a switch-case construct, where switch evaluates an expression.
- Example
~~~
var date = new Date();
switch(date.getDay()) {
case 6:
alert(“This is weekend.”);
break;
case 0:
alert(“This is weekend.”);
default:
alert(“Looking for a weekend.”);
break;
}
~~~
13
Q
JS “synchronized”
A
- JS keyword
- JS significant: avoid for variable/function names
- JavaScript does not have a synchronized keyword
- JavaScript is single-threaded. This eliminates the need for explicit synchronization
14
Q
JS “this”
A
- JS keyword
- JS significant: avoid in variable/function names
- Used to refer to the current object.
- Example
~~~
class Employee extends Person {
constructor(name, eid, salary) {
super(name);
}
get incsalary() {
return this.salary * 0.2;
}
}
~~~
15
Q
JS “throw”
A
- JS keyword
- JS significant: avoid in variable/function names
- Used in a try block to explicitly throw an exception object.
- 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;
}
~~~