This course has already ended.

JavaScript syntax basics: run-through

For your convenience, we have collected the basics of JavaScript in a cheatsheet.

Below, some questions to check that the JavaScript syntax is read and understood.

How is an external JavaScript loaded into a document

Where in a document can you include JavaScript?

How do you specify a block-scope variable tmp with value 2?

How do you specify a block-scope constant tmp with value 2 that will not be changed?

What is a block?

What is the term for raising var declarations to have a function-scope visibility even if the var variables were defined inside an inner-block of a function?

Which of the following code snippets are correct and not causing any errors?

// a
function sayHi() {console.log('hi!')}
sayHi()
// b
sayHi()
function sayHi() {console.log('hi!')}
// c
var sayHi = function sayHi() {console.log('hi!')}
sayHi()
// d
sayHi()
var sayHi = function sayHi() {console.log('hi!')}
// e
(function sayHi() {
  console.log('hi!')
})()
(function sayHi() {
  console.log('hi!')
})()

() in the end of the function above implies that ..

Data types can be primitives or objects

== comparison

=== comparison

How can you specify an array with initial values in JavaScript?

Define an empty array with two characters only (i.e., the max-length of the definition is two chars):

let array1 =  ...

Define an empty object (used as an associative array or map) with two characters only:

let object1 = ...

Functions in JavaScript

If a following JavaScript Snippet is executed, what will happen?

function examineArguments(a,b,c){
    console.log(a,b,c);
}
const a=1; const b=2; const c=3;
const d=4; const e=5; const f=6;
examineArguments(a,b,c,d,e,f);

Following JavaScript Snippet is executed, what will happen:

function examineArguments(a, b ,c){
    console.log(a, b, c);
}
const a = 1; const b = 2; const c = 3;
examineArguments(a, b);

Which of the following does specify a function that will return a number?

function addTenStupid(num) {
  for(i=0; i < 10; i++) { num += 1; }
  return num;
}

function addThousandStupid(num) {
  for(i=0; i < 100; i++) { num += addTenStupid(0); }
  return num;
}
console.log(addTenStupid(0));
console.log(addTenStupid(5));
console.log(addThousandStupid(1));
Posting submission...