Google News
logo
Swift - Interview Questions
What is the difference between let and var in Swift programming?
let,’ and ‘var’ are used to declare the functions in JavaScript. The main difference in both of them is that ‘let’ is block-scoped, whereas ‘var’ is the functional scope. As variable is represented by ‘var,’ and it is defined in the whole program in relation to ‘let.’
 
Example for defining "var" :
 
Syntax :
console.log(y);

var y=7;

console.log(y);

 

Output : undefined 7


Example for defining "let" :
 
Syntax :
console.log(y);

let x=7; console.l

og(y);

 

Output : Error
Advertisement