JavaScript Flashcards
What is ES6?
ES6 refers to version 6 of the ECMA Script programming language. … It is a major enhancement to the JavaScript language, and adds many more features intended to make large-scale software development easier. ECMAScript, or ES6, was published in June 2015. It was subsequently renamed to ECMAScript 2015
What is ECMA Script?
ECMAScript is a JavaScript standard meant to ensure the interoperability of web pages across different web browsers. It is standardised by Ecma International according to the document ECMA-262
European Computer Manufacturers Association Script - It is an organisation that create standards for technology
ECMA-262 is a standard published by Ecma International. It contains the specification for a general purpose scripting language.
Think of ECMA-262 as ECMAScript’s reference number.
There are many other ECMA standards
The specification defined in ECMA-262 for creating a general purpose scripting language.
Synonym: ECMAScript specification
While ECMA-262 is the name of the standard, it represents the scripting language specification ECMAScript.
ECMAScript provides the rules, details, and guidelines that a scripting language must observe to be considered ECMAScript compliant.
What is a JavaScript engine and examples?
A program or interpreter that understands and executes JavaScript code.
Synonyms: JavaScript interpreter, JavaScript implementation
JavaScript engines are commonly found in web browsers, including V8 in Chrome, SpiderMonkey in Firefox, and Chakra in Edge. Each engine is like a language module for its application, allowing it to support a certain subset of the JavaScript language.
A JavaScript engine to a browser is like language comprehension to a person. If we re-visit our example of the actions “walk”, “run”, “jump”, a JavaScript engine is the part of an “entity” that actually understands what these actions mean.
What is significant about Javascript support in browsers and ECMA Script?
With regards to browser support, people usually talk about “ECMAScript compatibility” rather than “JavaScript compatibility,” even though JavaScript engines parse and execute… well, JavaScript. This can be a little confusing, but there is an explanation.
What is a Javascript runtime and how does it differ from a javascript engine?
In short, the environment is where the code is running, the engine is what inteprets the code.
Runtime
- Runtime is the environment in which the JavaScript code runs and is interpreted by a JavaScript engine.
- The runtime provides the host objects that JavaScript can operate on and work with.
- Synonyms: Host environment
- For the server side, the JavaScript runtime is Node.js.
- Server-related host objects such as the file system, processes, and requests are provided in Node.js. Otherwise the runtime is a browser.
- An interesting point: different JavaScript runtimes can share the same JavaScript engine. V8, for example, is the JavaScript engine used in both Google Chrome and Node.js — two very different environments.
- Server-related host objects are for example window.alert(). This is a method from the browser. We’re executing code in the browser’s rungime environment.
- When you are running in Node environment you use console.log instead of window.alert because the window object is not available.
Javascript Engine:
- Translate source code into machine code that allows a computer to perform specific tasks.
What are let based variables in Javascript?
- The
let
keyword allows you to declare variables that are limited to the scope of a block statement or expression on which it is used, unlike the var keyword which declares a variable globally or locally to an entire function regardless of block scope1. - Variables declared with
let
are only usable in lines of code that occur after the variable is declared. -
let
variables may not be redeclared by a subsequent var or let. - Global let variables are not added to the global window objectlet variables are easy to use with closures (they do not cause race conditions)2.
What are constant variables in Javascript? Write the syntax
With ES6 you not able to reassign or redeclare a constant variable.
const varname = ‘test’;
What is the variable scope difference between var, const and let?
var, let and const is limited to function scope. Cant access outside function.
Let and const are block level scoped, but not var. Block level means within a thing like statements like If etc. Block level is accessible within a set of curly braces.
If you want to access let or const outside a block you need to declare it at a higher level.
What is an arrow function in ES6?
When should you use them?
Type the ES5 vs ES6 version.
* Arrow functions first introduced in ES6 (ECMA 2015 is the most recent)
* ES5 Does not have Arrow Functions.
* First of all, ArrowArrow functions make functions shorter by taking out the keyword function.
* Important to know that es6 arrow functions are nameless and cant be referenced again.
* If you want to reference the function, you need to assign it to a variable like in the example below.
* In the concise version you dont need a body or return statement. You can write short functions much easier.
They were added:
* Reduces lots of code and makes the mode more readable.
* Arrow function syntax automatically binds “this” to the surrounding code’s context.
* Writing the arrow => is more flexible as compared with the writing function keyword.
So for example in ES5 it was:
function square (x){ return x; }
Verbose es6: const squareArrow = (x) =\> { return x; }
Consise es6:
const SquareArrow = (x) => x*x;
(Assumed there is a return statement)
console.log(squareArrow(9));
Without Parenthesis
hello = val => “Hello “ + val;
What does the “this” keyword refer to?
- In a method, this refers to the owner object.
- Alone, this refers to the global object.
- In a function, this refers to the global object.
- In a function, in strict mode, this is undefined.
- In an event, this refers to the element that received the event.
- Methods like call(), and apply() can refer this to any object.
- When used alone, the owner is the Global object, so this refers to the Global object.
- In a browser window the Global object is [object Window]
- In strict mode, when used alone, this also refers to the Global object [object Window]:
fullName : function() { return this.firstName + " " + this.lastName; }
So, in a function, this refers to the Global object [object Window]. function myFunction() { return this; }
JavaScript strict mode does not allow default binding.
So, when used in a function, in strict mode, this is undefined.
"use strict"; function myFunction() { return this; }
In HTML event handlers, this refers to the HTML element that received the event:
Click to Remove Me!
The call() and apply() methods are predefined JavaScript methods.
They can both be used to call an object method with another object as argument.
In the example below, when calling person1.fullName with person2 as argument, this will refer to person2, even if it is a method of person1:
var person1 = { fullName: function() { return this.firstName + " " + this.lastName; } } var person2 = { firstName:"John", lastName: "Doe", } person1.fullName.call(person2); // Will return "John Doe"
What are the characteristics and differences between Functions and Methods in JS?
JavaScript Functions:
- A block of code written to perform some specific set of tasks.
- Defined using the function keyword, followed by Name and optional parameters. Body of function is enclosed in Curly braces
Features:
- The function is executed when something calls/invokes it.
- The name may contain letters, digits, dollar signs, underscore.
- Parameters are listed inside round parenthesis after the name of the function.
- Arguments are values a function receives when it is invoked.
- When the control reaches the return statement, js will stop executing and the value is returned to the caller.
Method
- Is a property of an object that contains a function definition.
- Methods are functions stored as object properties
Features:
- Actions that can be performed on objects are what we term JavaScript methods.
- The objects can also be called without using parenthesis.
- This refers to the owner object in a method.
Differences
- A function can be called directly by its name. A method consists of a code that can be called by the name of its object and its method name using dot notation or square bracket notation..
- Data passed to a function is explicit. A method implicitly passes the object on which it was called.
- A function lives on its own. A method is a function associated with an object property.
What is the javascript Map method and how do you write it?
Map created a new array from an existing array and populates the it with the results.
This example uses an arrow function.
Const testmessage = this.cities.map ((city) => {
return this.name +’ message ‘+ city;
};
return testmessage;
What is the relationship between Javascript and ECMAScript
JavaScript is a general-purpose scripting language that conforms to the ECMAScript specification. The ECMAScript specification is a blueprint for creating a scripting language. JavaScript is an implementation of that blueprint. On the whole, JavaScript implements the ECMAScript specification as described in ECMA-262.
Why is it called JAVAscript?
Initially it was called LiveScript, but it was decided that positioning it as a younger brother of Java would be better. It later became more independent with its own specification called ECMAScript.
What are some examples of Javascript engines?
Javascript engines are also sometimes called a JavaScript Virtual Machine.
V8 - chrome, opera, edge,
Spidermonkey - Firefix