Declarations Flashcards

1
Q

Syntax to declare variable with block scope? (2)

A

Let - declares a block scope local variable, optionally initializing it to a value. *Let cannot declare a variable at global scope.
Const - declares read-only variable with block scope

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Limitations to variables declared with ‘Let’

A
  • not hoisted; temporal availability when block is executed
  • cannot create variable on global object
    ex: Cannot check properties outside of block; cannot access within block statements like Switch{ }
  • backwards compatibility issues (ES6+)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When are double quotes required in JavaScript?

A

JSON requires double quotes for strings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is wrong with this syntax?

var a=b=c=10 ;

A

b and c are global variables. oops

  • Do not chain var declaration AND assignments
    var a, b, c; //ok
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the scope of a parameter passed to a function?

A

Parameters are local variables (no need to re-assign to var within the function body).
- A parameter passed to a parent function will be in closure scope (is known to IIFE it returns)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Are identifiers case-sensitive?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

“typeof” operator applies to?

A

Primitives

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

“instanceof” operator applies to?

A

Objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a statement, and how can it be identified?

A

Statements “do things”. A sequence of statements is a program.

To prevent ambiguity, terminate statements with semicolon ;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the diff between a statement and an expression? Are they interchangeable?

A

Expressions produce values

- Expressions can be used where a statement is expected (“expression statement” ends with a ‘;’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How does JS differentiate a block statement from an expression?

A
  • Expressions cannot start with curly brace { }
  • Expressions cannot start with function keyword
  • Block statements do NOT end with semi-colon

The following are block statements:
{
foo: bar(3, 5)
}

function foo() { }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you turn a block statement into an expression? Examples?

A

( ) can transform blocks into expressions
ex.1: Object literal ({dog:Floyd})

Create function expression ending with semicolon
var f = function( ){ }; 

Create IIFE with parentheses and semicolon
(function( ) { …})( );

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is ‘lexical scoping’ ?

A

The word “lexical” refers to the fact that lexical scopinguses thelocation where a variable is declared within the source code to determine where that variable is available.Nested functions have access to variables declared in their outer scope.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly